When dealing with figures including several plots, sometimes you want to select a number of plots. The way I usually do it is opening the plot browser in the view section and it mostly is good enough. As you can see in the following snapshot, the plot browser does not show more than a specific number of plots, and is saying and 89 more ...
How can I access the other 89 plots? Is there any setting that you can force MATLAB to show all the plots in the plot browser?
In the command line, you can use
plotList = findobj(get(gca,'Children'),'Type','Line')
This will give you a list of handles to all of your plots. You can perform actions on any of these plots. For example - changing the color of the second and fourth plots to red:
set(plotList([2,4]),'Color','r')
Removing the third and sixth plots:
delete(plotList([3,6]))
Related
Similar to what we can do with the subplot command in MATLAB to have many plots in a single figure, How can I plot different graphs in same figure using Simulink?
Note:
I am not asking about multiplotting which I already know how to do that using vector concatenate + scope but it gives me overriding plots. I am unable to find a way that I could have a separate subplot for each function.
Any help?
Have multiple inputs for your scope (image shows right-click menu)
Show multiple plots from the layout menu (up to 16x16 plots) of the open scope
Voilà, subplots! As per the documentation, the first n traces will be shown in the first n subplots of the layout. Any traces which can't be shown individually will all be grouped within the last subplot.
Often in Matlab we would plot a figure with many subplot axes, but they are all tiny.
In the prevalent UX paradigm, you would expect to be able to double-click such a small plot to have a closer look using the entire screen space.
Typically this is the reason I avoid using subplot, but plot many individual figures instead — so I can move them around on the screen and double-click on their titlebars which (on Windows) maximises the figure to full screen. (Double-click again, and it returns to its normal size.)
However, the advantage of subplot is that the set of plots is grouped in one panel. When I'm plotting many such groups (each with a dozen separate subplot axes), having that many individual figures becomes hard to work with.
So, is there a way to enable this functionality in Matlab already?
Combining parts of these three posts, here's what I have so far:
h = subplot(2,2,1);
line(1:10, rand(1,10));
set(h, 'buttondownfcn', ['h=gca; hc = copyobj(h, gcf);' ...
'set(hc, ''Units'', ''normal'',' ...
' ''Position'', [0.05 0.1 0.8 0.85],' ...
' ''buttondownfcn'', ''delete(gca)'');']);
It's not perfect, but it works.
Click on the axes:
Click on the expanded axes, and it disappears:
Note that this still allows you to pan, zoom, and "rotate 3D" the resulting axes. Selecting the arrow tool actually enters "Edit Mode", so it's better to unselect the tool you are using instead. For example: if you were zooming in, click on the zoom-in icon again to deselect the tool. Clicking will then "collapse" the blow-up of the axes.
The limitation so far is that you can sometimes see parts of the underlying little subplot axes underneath. If someone can recommend an elegant way to hide them, that would be a nice improvement.
EDIT Learning from this answer (using a uipanel to prevent other contents from showing through), I now have turned the solution into this:
gcaExpand.m:
function gcaExpand
set(copyobj(gca, uipanel('Position', [0 0 1 1])), ...
'Units', 'normal', 'OuterPosition', [0 0 1 1], ...
'ButtonDownFcn', 'delete(get(gca, ''Parent''))');
end
gcaExpandable.m:
function gcaExpandable
set(gca, 'ButtonDownFcn', [...
'set(copyobj(gca, uipanel(''Position'', [0 0 1 1])), ' ...
' ''Units'', ''normal'', ''OuterPosition'', [0 0 1 1], ' ...
' ''ButtonDownFcn'', ''delete(get(gca, ''''Parent''''))''); ']);
end
The first one expands the current plot immediately. The second one adds the functionality where clicking onto the plot expands it. In both cases clicking again returns things back to normal.
I've placed them into the directory with all my other custom Matlab functions that I'm using on a day-to-day basis. The above can also be included in functions to be sent out.
Initially, I was going to write a custom version of subplot that applied gcaExpandable automatically, but that didn't work, because commands like plot erase the ButtonDownFcn property (as well as all other properties, except the position). According to this answer, we can avoid resetting those properties by changing the NextPlot to 'replacechildren', but that has side-effects. For example, plot no longer automatically rescales the axes. Therefore, the cleanest solution so far seems to be as above.
I have a series of histograms being plotted along side each other in a bar3 plot. I'd like to take advantage of the plot browser to turn on and off various histograms so I can do side by side comparisons. You can see from the properties Inspector that I've altered the display name for one such surface, the third, that is being updated in the legend but not in the property browser.
There's also a misregistration of the colors you see in the legend to that of the actual plot. The legend is accurate only when I have all surfaces checked for display.
I'm using MATLAB Version 7.13.0.564 (R2011b)
Thanks for helping
Toggle the legend off and on with legend('off') followed by legend('show'). Try also legend('toggle').
The MATLAB surf plot below is essentially two plots plotted adjacent to each other. For clarity, I have included some code below used to prepare the plot:
band1 = horzcat(band1, eSurface2(:,:,1));
band2 = horzcat(band2, eSurface2(:,:,2));
surf(band2,'DisplayName','band2');
surf(band3,'DisplayName','band2');
I would like for the y axis numbering to restart at the start of the second graph. How do I go about doing that?
You can use the 'YTick' and 'YTickLabel' properties of the axis to control the ticks, this way you can make it start from zero for the second graph. It will require some trail and error to get it right. See the relevant doc here (you'll have to scroll all the way to the bottom of the page).
Take advantage of the following feature of 'YTickLabel': "If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels".
This should be a problem with a trivial solution, but still I wasn't able to find one.
Say that I have 2 matlab figures fig1.fig, fig2.fig which I want to load and show in the same plotting window.
What should I do?
I mean, I am pretty sure that I can accomplish the task using some low(er) level graphic command which extracts contents from one image and put them in the second one, nonetheless I cannot believe that there is not any high level function (load fig2 on top of fig1) that does this...Comparing 2 plots (unfortunately already saved) is a very common task, I'd say.
Its not clear if you want to extract data from the figures and compare the data, or if you want to combine the plots from two figures into a single figure.
Here is how you combine two figures into one (if thats what you want to do)..
First load the figures:
fig1 = open('FigureFile1.fig');
fig2 = open('FigureFile2.fig');
Get the axes objects from the figures
ax1 = get(fig1, 'Children');
ax2 = get(fig2, 'Children');
Now copy the hangle graphics objects from ax2 to ax1. The loop isn't neccesary if your figures only have a single axes
for i = 1 : numel(ax2)
ax2Children = get(ax2(i),'Children');
copyobj(ax2Children, ax1(i));
end
Note This example assumes that your figures have the same nubmer of axes and that you want to copy objects from the first axes in the second figure to the first axes on the first figure. Its up to you to figure out the proper indexing if the axes indices aren't lined up.
The answer slayton gave is good. Here's another tip: If you have two plots opened in two separate Matlab figure windows, don't forget you can point-and-click copy the proper plots. Do this by clicking the arrow pointer in the Matlab figure window, and then clicking on the plotted line. Copy the (plotted line, textbox, etc...) object. Then, similarly select the axis in the other Matlab figure window and paste it.
I give this 'silly' solution because it has proven to be useful in in collaboration meetings. Point-and-click copying in front of someone (like your adviser) communicates exactly what curves are being compared, and it prevents you from having to fire up code in front of others.
You can also go to File in the menu, Generate Code, for each plots.
Then copy and paste both in the same mfile, with a "hold on" in between and changing details related to the appearance.
Then run the new m-file.