How to define the upper limit of y-scale in a log plot

Hello, i need to plot some graphs of some curves in logarithmic scale on the y-axis and the y-scale must range from 0 to 10^-5. I want to superpose the curves on the same image, thats why the scale must be the same for all plots. I'm currently using semilogy to get a log scale, but the range is completely messed up. I've tryed using
set(gca,'yscale','log')
but again, i don't have control on the upper limits of the y-scale. What can i use to resolve this? Thanks.

 Akzeptierte Antwort

dpb
dpb am 4 Sep. 2015
You don't give any data nor attach a plot to see the issue specifically, but you set fixed axes limits on log axes the same way as you do for linear ones--use ylim (or set for low-level control or in conjunction with other properties on the axes in one call).
Simple example--
y=[10*rand(10,1), 1E5*rand(10,1)];
hAx=semilogy(y);
ylim([1,1E6])
ylim([.5,4E5])
Salt to suit for your particular case...

Weitere Antworten (3)

Heyang Qin
Heyang Qin am 12 Jan. 2019

1 Stimme

The problem of cannot set axis range such as ylim or xlim in log scale is becaue you cannot set log value to 0. Any value other than 0 will work.

1 Kommentar

dpb
dpb am 22 Sep. 2024
"...you cannot set log value to 0."
You can set the x|ylim property to include zero; MATLAB will silently do the equivalent of the 'tight' limitmethod option for the selected axis. The displayed lower limit will become the first/lowest magnitude value in the X|YData array, but xlim will return the actual set values from the input vector including '0' if specified. log axes are coded to just ignore 0 and negative data; you get a warning if you plot with such, but the positive values are plotted and then the limits act like any other numeric axes programmatically, with just the above nuances about what is actually displayed.

Melden Sie sich an, um zu kommentieren.

Hi,
Please try this code:
set(gca, 'YScale', 'log')
ylim([0 1e-5])
Roland
Roland am 22 Sep. 2024

0 Stimmen

can xlim be 0.3

3 Kommentare

dpb
dpb am 22 Sep. 2024
??? One limit can be, certainly, but xlim() requires a 2-vector, not just a single value and the two limits cannot be identically the same.
do the two numbers need to be powers of 10?
No

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 4 Sep. 2015

Kommentiert:

am 22 Sep. 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by