How to fix the figure plot always being above on the screen?

Dear all friends,
When I generate a figure plot in matlab, how could we make the plot always being above on the screen?
It is unconvient when I debug my code row by row and the plot would be disappear, and I have to adjust the matlab window to make figure plot and matlab window being shown together.
is there any way to achieve the figure plot fixed above on the screen ?

More Answers (3)

Hello,
You may set the figure property of WindowStyle to 'modal' :
f=figure;
f.WindowStyle='modal';
PS: 'docked' is another option if you don't want the figure always cover a part of screen.

1 Comment

Dear friend,
I find the windowstyle did not solve my problem. I may not explain my question clearly. For the following sccren shot , when I debug my code, for example, it runs to line 34, the figure plot is shown. However, when clicking step-to-run, the figure plot is disappeared. the figure moves to the back on the screen. I have to adjust matlab window to find the figure plot then continue debugging. It is not convenient.
so i just wonder if there is some codes that can make the figure plot always been show on the screen, even when clicking other buttons in matlab window, the figure plot should not be pushed back and disappear.
I prefer writing codes to achieve this, not to make efforts on the figure plot. Because I am asking this question just because I dont want to be interrupted when debugging. if I still have to click sth on the figure plot, interruptions in debugging still happen and what is the actual difference with adjusting matlab window to achieve this?
So if there is some guidence to writing codes to achieve this. it would be very great!

Sign in to comment.

From your query, I can guess you want to position the plot graph at some point on the screen which would help you to debug your code.
Take the following example and I hope you can edit the pixel location according to your need.
f1= figure;
x=1:10;
y=sin(x);
plot(x,y);
figure(f1);
f1.Position(1:2)= [0 0]
For further information, check this out: https://www.mathworks.com/help/matlab/ref/figure.html

1 Comment

Dear friend,
Thanks for your help. Still i dont achieve my expectations well. I may not explain my question clearly. You may find my explanation in the first respondent's comment.

Sign in to comment.

Hello YINGGANG
It is my understanding that you want to fix the figure plot on the screen , so that both the code and plot appear together and it will be easy for you to debug the code.
You can achieve this by reproducing the steps as follows :
1.You need to dock the figure window to matlab window using the dock option(curved arrow) given in figure window.
2.A seperate figure window will appear beside the editor window in the matlab.
3.Click and hold on the docked figures window titlebar and pull the cursor and adjust according to your convinience .
or alternatively you can use a live script where as you code and run , the results/plots appear to the right.So you can look at the code and the results at a time
You can refer to the live script documentation Create Live Script for more details

5 Comments

Dear Shyam,
Thanks for your help. As you advised, i can finally got what i need. but every time I need to manipulate the figure with curved arrow click and arrange the editor and figure windows to show them together. is there any way for writing some codes to achieve this ?
by the way , i dont mind where the figure position is on the screen (of course, it can't block the code sight), only I just want to through code running to achive figure plot is always shown on the screen?
Once you have moved one plot to the place you want, you can ask MATLAB to display the Position property of the figure.
fig = gcf;
FIGPOS = fig.Position;
disp(FIGPOS)
671 661 577 433
After that, you do not need to move each new plot: you just set its Position property to the position that you found worked well.
Dear friend,
Thanks for your help. Still i dont achieve my expectations well. I may not explain my question clearly. You may find my explanation in the first respondent's comment.
If the code window is always the same size, then once you have manually positioned a figure once you can do
Nice_Figure_Position = get(gcf, 'Position');
and after that, every time you generate a new figure, you can do
set(gcf, 'Position', Nice_Figure_Position)
Hi,
Thanks for updating.
You may still not understand my problem. The main problem is during debugging, the figure plot, once generated , is automatically pushed back to the MATLABT window when codes runs to next line. Your code is just allocate the figure to some certain position, but if continue clicking step-tu-run, when moving to next line, the figure plot still disappear.
you may find what I am trying to say on first respondent's comment. you may see the screen shot to find what actually my problme is.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 4 Jul 2022

Answered:

on 7 Jul 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!