Matlab line overlaps axis when values ​​are zero

I drew a figure with several lines on it, and I noticed that the lines for the plot overlap the x axis when they are zero. Is there a way in which I can essentially get the x axis to build on top, not for rows?

Here is the MWE that does the same (I did not put in my exact code, since my dataset is quite large).

xdata=1:1:10;
ydata=[1;0.8;0.6;0.4;0.2;0;0;0;0;0];
line(xdata,ydata)

After I build the lines (several for each plot in my case), I do different things using the axes to 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 drawn on top of the lines or not.

I had a search on the Internet, but I could not find anything to do with this.

+4
source share
2 answers

The answer given by Louis is a good workaround, but the official way to solve this problem is to use the property layerof the axis object, see the manual . To build an axis on top of the data you make,

set(gca,'Layer','top')

To automatically do this for all your charts, you can put the following line in startup.m:

set(0,'DefaultAxesLayer','top')

You didn’t come up with such answers yourself, I discovered this trick only after I asked more or less the same question on comp.soft-sys.matlab many years ago . See also this SO question .

+5
source

, , x , :

hold on
a = axis; %// gives xmin xmax ymin ymax
cx = get(gca,'Xcolor'); %// color of x axis
plot([a(1) a(2)], [a(3) a(3)], 'color', cx)

y, , , :

cy = get(gca,'Ycolor'); %// color of y axis
plot([a(1) a(1)], [a(3) a(4)], 'color', cy)
+3

Source: https://habr.com/ru/post/1529396/


All Articles