Matlab: making the grid in plot logarithmic

2020-04-20 16:08发布

问题:

I have plotted to vectors against each other, and they are already logarithmic and everything is fine with that. But now that I have my plot i want the grid to be logarithmic. I write "grid on" in my code, and I think there should be a way to do this in the plot, but I can't remember how. How do I make the grid logarithmic?

回答1:

If you use loglog, semilogx or semilogy instead of plot, the grid will automatically be on a log scale for the corresponding axes when using grid on.



回答2:

If you have already plotted the axes, you can execute the following on the command line:

set(gca,'yscale','log') %# to set the y-axis to logarithmic
set(gca,'xscale','log') %# to set the x-axis to logarithmic

Have a look at axes properties to find out what else you can modify.