logarithmic axis when using area plots?!

19 ビュー (過去 30 日間)
arnold
arnold 2013 年 4 月 28 日
Hi,
I have plot containing two area plots:
area(x1,y1);
hold on
area(x2,y2,'FaceColor','red');
axis auto;
Now I'd like to make the x-axis logarithmic via:
set (gca, 'Xscale', 'log')
This creates logarithmic x-axes, however it deletes the color of the first area plot (leaving just a line plot) and messes up the range. Any suggestions on how to create a semilog area plot with two areas?
Thanks Arnold!
PS: Sorry that the Text Markup doesn't seem to work here either (or only in my view?!)
  2 件のコメント
the cyclist
the cyclist 2013 年 4 月 28 日
Can you create a small example that exhibits the problem? I'm guessing your original plots goes through zero, which may cause the logarithmic axes problems.
arnold
arnold 2013 年 4 月 28 日
Here you go
%%Example
d = 30;
x1 = 0:1:d;
y1 = exp(-0.05 * x1);
x2 = d:1:100;
y2 = y1(end)*exp(-0.2*(x2-d));
area(x1,y1);
hold on
area(x2,y2,'FaceColor','red');
hold off
axis auto
set (gca, 'Xscale', 'log');
It really seems, that the inclusion of the zero in x1 is the problem. Obviously I get why x= zero can't be displayed but since the line plot of y1 is still visible, who would have thought of that. It still seems like a bug to me, but starting at x1(2) is an option.
cheers

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

採用された回答

Ingo Schalk-Schupp
Ingo Schalk-Schupp 2013 年 9 月 4 日
The problem is that your x data contains a value of zero, the logarithm of which is undefined. There is no zero on a logarithmic axis. To avoid this, simply start your area, for instance, at an x value of 1 instead of 0:
x1 = 1:1:d;
If you additionally want a logarithmic y axis, the same problem arises because by default, the painted area face goes down to zero. However, you can specify a different BaseValue like this:
area(x2, y2, 'FaceColor', 'red', 'BaseValue', 1e0)
Cheers

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by