Given a plot of three curves in a .fig file I'd like to add another plot (with hold all
and plot
), but put it behind one of the already existing curves (i.e. make sure the last original curve stays the foreground one). Can this be achieved without having to extract the plot data and re-plotting?
Running MATLAB with the –nojvm option, the figures are created as X11 windows. So you can bring them to the front, as you had experienced previously, by double clicking the X11 icon in the Dock. In this case, it brings the current figure to the front, but you can use any available figure handle in place of “gcf”.
By default the order of the lines in the legend is the same as they are plotted. The easiest way is to just plot them in the order you want the legend to appear. If that is not feasible, then you can change the order of the lines as they are stored in the 'Children' property of the axes.
If you know the handle of line you want on top (e.g. because you called h = plot(...)
, you can use uistack
uistack(h,'top')
Alternatively, you can manipulate the order of children of your current axes directly. The following puts the last-most curve on top.
chH = get(gca,'Children') set(gca,'Children',[chH(end);chH(1:end-1)])
The resolution given by @Jonas using 'Children'
property does not work in its given format. It should be modified as follows:
chH = get(gca,'Children') set(gca,'Children',flipud(chH))
When the image has a legend, the get(gca,...)
and set(gca,...)
pair result in an error: "Error using set. Children may only be set to a permutation of itself"
In that case, I used the GUI select tool of the figure to select the axes objects, then get and set work only with the plots as required and not the legend as well. After calling set, you have to refresh the legend by calling legend(...)
. I had 5 plots that I needed to reorder. When unsure about the order, permute plots two at a time, refresh the legend and see if that is the order you wanted
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With