I have plotted a figure with multiple lines on it, and I have noticed that the lines for the plot overlap the x-axis when they are zero. Is there a way that I can essentially get the x-axis to plot on the top, rather than the lines?
Here is a MWE that does the same thing (I haven't put my exact code up as my dataset is quite big).
xdata=1:1:10;
ydata=[1;0.8;0.6;0.4;0.2;0;0;0;0;0];
line(xdata,ydata)
After I plot the lines (multiple per plot in my case), I do various other things with the axes so I get what I need (including adding a secondary set of axes). None of this seems to make any difference as to whether the x-axis is plotted on top of the lines or not.
I did have a search online but couldn't find anything to do with this.
The answer given by Luis is a nice workaround, but the official way to solve this problem is to use the layer
property of the axis object, see the manual. To plot the axis on top of the data you do
set(gca,'Layer','top')
To automatically do this for all your plots, you can put the following line in your startup.m
:
set(0,'DefaultAxesLayer','top')
This kind of answers you do not make up yourself, I only discovered this trick after asking more or less the same question on comp.soft-sys.matlab many years ago. See also this SO question.
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