How to avoid log(0) within an area plot?

13 ビュー (過去 30 日間)
Rene
Rene 2013 年 12 月 8 日
編集済み: Rene 2013 年 12 月 8 日
Hi there, I'm pretty much a greenhorn in using Matlab so and now I'm facing a problem with an area plot. I'm trying to create an area plot containing several areas.
So far so good. But when I'm setting the y-axis on logarithmic scale the colors of my areas disappear. I already found out that it is due to the zeros in my data set which I cannot avoid and I don't want to. Does anyone know how I can tell Matlab not to calculate log(0)=-Inf but leave it as a zero?
So here is what I got so far:
Magnitude4 = area(Year,M4,'FaceColor','b') axis([1960 2011 1 1500]); set(gca, 'yscale', 'log') hold on Magnitude5 = area(Year,M5,'FaceColor','r') axis([1960 2011 1 1500]); set(gca, 'yscale', 'log') hold on Magnitude6 = area(Year,M6+eps,'FaceColor','c') axis([1960 2011 1 1500]); set(gca, 'yscale', 'log') hold on Magnitude7 = area(Year,M7+eps,'FaceColor','y') axis([1960 2011 1 1500]); set(gca, 'yscale', 'log')
It would be great if anyone could help me with this issue.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 8 日
編集済み: Azzi Abdelmalek 2013 年 12 月 8 日
Y(~Y)=1
plot(y)
set(gca,'yscale','log')
  1 件のコメント
Rene
Rene 2013 年 12 月 8 日
編集済み: Rene 2013 年 12 月 8 日
Thanks Azzi, but here I'm facing the situation that the areas aren't filled with the color they are supposed to. They are filled with color of the axis.Do you happen to know how I can fill the areas below the plots?

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


Wayne King
Wayne King 2013 年 12 月 8 日
Instead of plotting the y-axis on a log scale, you can first take the log10() or your data and then set the -Inf to 0.
X = randi([5 10],10,10);
X(2,1) = 0;
Y = log10(X);
Y(Y== -Inf) = 0;
  3 件のコメント
Wayne King
Wayne King 2013 年 12 月 8 日
編集済み: Wayne King 2013 年 12 月 8 日
If you want the labels as 10^power, then see Azzi's solution. But I'm very surprised that say the maximum was only 1400, but log10() produced an 8. That doesn't make sense. Taking log10() will give a value only slightly greater than 3.
Rene
Rene 2013 年 12 月 8 日
You're right. I only set the log() instead of log10(). Thanks for the hint. With Azzis hint it worked quite well for the y-axis. but now the areas aren't filled with any color but the axis color.

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

カテゴリ

Help Center および File ExchangeScopes and Data Logging についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by