how to edit different axis manually in matlab's figure? - matlab

I am using a plotyy in matlab to ploy two data set in a same figure. I want to use the figure menu to edit the axes property manually. But I found that I can only select and edit the first axis but not the second one. Of course, I can edit those with command 'set' but just wonder how to select the second axis.

In your figure, click "View -> Plot Browser", the second axis will be listed at the bottom and can be selected.

Related

How to show the complete legend in the plot window of Dymola?

I am trying to plot some of my results in Dymola, but when I plot a few curves in one graph, the legend can't show completely, is there any setup I could use to let the legend show completely?
You can select from various legend styles in the plot window setup.
In your case Right would be the choice.

Default display of axes in Matlab Gui

I tried using axes for displaying images in Gui.But, before displaying any images, the axes is shown with a plot figure while running the GUI, something like below.
You can see the default axes being displayed. Is there a way to display the axes in running GUI without displaying these plot figures? So that when the image is not displayed in the axes, nothing is displayed. Thanks in advance.
UPDATE 1
I have used 9 axes here, thus the long trail of y axis.
Yes, you can use
axis off
To remove the axes from the empty plots. Then use
axis on
When you actually plot something to bring them back.
Best,

How to specify which axes to plot in a GUI

I am new to GUI. But I have two axes in GUIDE GUI and wish to specify the one to plot a figure, but I can't find handles.axe1 anywhere. Can anyone help me with this?
Since you built your GUI with GUIDE you can easily access the Tag property of each axes in the property inspector.
Once you know the tag of each axes, you can choose where to plot stuff using the first argument of plot:
plot(TagofAxes,x,y)
or using imshow, using the Parent property:
imshow(YourImage,'Parent',TagofAxes)
and so on.

how to change the sequence of the legend

I want to change the sequence of the legend.
See the figure. I want the sequence to be: green and data2, blue and data3, black and data4, red and data1.
Could anyone give a demo?
Change the order in which the plots are added to the figure, and then call legend normally. That should do it.
You can also do it as follows. First get handles to the individual plots:
h1 = plot(1:5);
hold on
h2 = plot(11:15, 'r');
Then call legend specifying the order:
legend([h1 h2],'plot1','plot2')
or
legend([h2 h1],'plot2','plot1')
In case, you have already made the plots or if you added some plot at the end, which want to reorder to somewhere in middle, you can try this way:
1) Go to show Plot Tools and Dock Figure.
2) Delete the data (which you want to move to bottom). Then undo delete.
3) Refresh legend.

How to add a x-axis line to a figure? (matlab)

I want to add a x-axis line at 0 to a Matlab figure so that I can compare my data to see if it is positive or negative when saving the figures to a jpg. What is the best way to do this? I know you can use line() but it just seems cumbersome because you need to specify the x and the y ranges. Is there an easier way?
There exist an undocumented function graph2d.constantline:
plot(-2:5, (-2:5).^2-1)
%# vertical line
hx = graph2d.constantline(0, 'LineStyle',':', 'Color',[.7 .7 .7]);
changedependvar(hx,'x');
%# horizontal line
hy = graph2d.constantline(0, 'Color',[.7 .7 .7]);
changedependvar(hy,'y');
The nice thing is that it internally implements a listener for the axes limits (handles change like pan, zoom, etc..). So the lines would appear to extend to infinity.
You could get this x range directly after the figure has been created. It goes a little something like this:
x=-2:5;
y=x.^2-1;
figure()
plot(x,y);
xlim = get(gca,'xlim'); %Get x range
hold on
plot([xlim(1) xlim(2)],[0 0],'k')
Note that if you do any manual zooming out in the figure, the line might have to be redrawn to go over the entire new x range.
I don't believe there is a built-in way that is more convenient. I use hline() and vline() from FileExchange, which work like a charm:
http://www.mathworks.com/matlabcentral/fileexchange/1039
A vline and hline command like in GNU R would be great, but I could not find a shorter solution than
plot(1:10,sin(1:10));
line(xlim,[0 0],'Color','r')
Draw your data by plot() command or stem(). A figure window will open.
Then on the figure window, click on the [insert] command from the
menu bar, a drop-down menu will appear.
From this menu click on the [line] command, now the shape of the
cursor will change into a plus sign.
Now you can draw a line anywhere you want, either horizontal or
vertical or slanted.
You can change the properties of line by right clicking on the
line, a menu will appear from which you can choose your desires
properties.
If you want to have some ticks on the line then you can use add
text option, and place text where ever you want.
If you would like to have a code for your figure, click on [file]
menu and then click on [generatecode] option, a new text editor
window will open, you can save this code for further use. Good luck.
Since MATLAB R2018b there is yline for this purpose:
yline(0)
draws a horizontal line at y==0.