フィルターのクリア

how to set y-axis as log scale?

4,503 ビュー (過去 30 日間)
Rohit Bhoi
Rohit Bhoi 2016 年 4 月 15 日
コメント済み: Adam Danz 2024 年 7 月 12 日 15:08
I am plotting x-y plot using plot function. I want to set only y-axis as log scale and x-axis as linear? How to do that? I used loglog function but it scales both axis but I want only Y.

採用された回答

Walter Roberson
Walter Roberson 2023 年 9 月 22 日
編集済み: MathWorks Support Team 2023 年 9 月 22 日
The best way to create that type of axes is to use the semilogy function. Alternatively, you can set the ‘YScale’ property on the axes:
set(gca, 'YScale', 'log')
***Update from Mathworks Support Team - September 2023***
As of R2023b, you can also use the 'yscale ' function. 
  22 件のコメント
Mr Thadi
Mr Thadi 2024 年 7 月 4 日 5:31
Thank you Mr walter,
i have attached one image,
in that my data file having values from 100 to 14000.
if i plot histogram without x axis set properties it showing like figure 'A', in that bins starts from 0-300,300-600...etc like that.
but if i use set (gca,'xscale','log') command to the x scale it showing initial bin from 300-600,600-900....etc.you can see in figure 'B'
my question is what about values in between 0-300 from figure 'B' , why these are not appearing how to solve it,if i want to get xscale in log values histogram initial bin from 0-300,300-600...etc are needed to change properties in that to command?can you please explain me
i can provide my data file also to you
Adam Danz
Adam Danz 2024 年 7 月 12 日 15:08
This issue arises because the first bin edge is at x=0 and log(0)=-inf which cannot be represented graphically.
Assuming there are no data less than or equal to 0 and no bin edges less than 0, you could set the first bin edge according to the smallest value in the data.
x = rand(1,1000)*10000;
minPositiveValue = min(x(x>0),[],'all');
minbin = 10^floor(log10(minPositiveValue));
ax = axes();
h = histogram(ax, x);
ax.XScale = 'log';
if h.BinEdges(1) == 0
h.BinEdges(1) = minbin;
end

サインインしてコメントする。

その他の回答 (2 件)

Toshia M
Toshia M 2023 年 9 月 20 日
Starting in R2023b, you can change the scale of any axis after you create the plot by calling the xscale, yscale, or zscale function.
For example, create a plot of two vectors x and y. Then set the scale of the y-axis to logarithmic.
x = 1:100;
y = x.^2;
plot(x,y)
grid on
yscale log

Rohit Sinha
Rohit Sinha 2022 年 4 月 27 日
The easiest way to do this is simply use the following command instead of plot
semilogy(x,y);
This will plot x axis on a linear scale and y axis on a log scale. Similarly, if you want to plot x axis on log scale and y axis on a linear scale, you can use
semilogx(x,y) ;
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 27 日
semilogy() is the first thing I mentioned in my answer in 2016.
Nicholas Santiago
Nicholas Santiago 2022 年 11 月 4 日
yo i totally missed that I generally only read the bold stuff, thanks a ton!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by