How can I plot negative value with log scale?

388 ビュー (過去 30 日間)
Qing-quan Zhi
Qing-quan Zhi 2016 年 6 月 27 日
コメント済み: Jungmin kim 2023 年 6 月 2 日
I want plot some data which varies over many order (from 1e6 to 1e-4) with some positive and negative values in log scale(like the attached picture), but the matlab function -- 'loglog' can only plot either positive or negative data in one drawing. Is there any function can plot both the positive and negative data? just like the 'symlog' scale in matplotlib. Or any other alternative way?
  5 件のコメント
Qing-quan Zhi
Qing-quan Zhi 2016 年 6 月 28 日
The scale is very useful when displaying the data over many order. An frequently-used method is transforming data by the formular t = sign(x)*log(abs(x)), then plot the (t,y) instead of (x,y), and modify the yTickLabel manually.
dpb
dpb 2016 年 6 月 28 日
Yeah, but...what do you do about the issue that the last decade covers range of infinite number of decades on the same scale as the previous that is actually only one? Truncate data to eliminate it or what???

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

採用された回答

Robert
Robert 2016 年 6 月 28 日
編集済み: Robert 2016 年 6 月 28 日
Rather than use the transform you mentioned in your comment,
t = sign(x)*log(abs(x))
you could use
t = sign(x)*log(1+abs(x)/10^C)
which would preserve the continuity of your plot across zero and allows you to tune the visibility into values near zero. As long as you are careful to label the axes appropriately I don't think it is fair to call this incorrect or deceptive.
You can edit the Tick marks and labels and even modify the MinorTicks of the [X,Y,Z]Ruler object as occurs when you use set(gca,'XScale','log') or the like.
Inspired by your question, I made a function called symlog to do just this and put it on the File Exchange here.
An example plot:
x = linspace(-50,50,1e4+1);
y1 = x;
y2 = sin(x);
y3 = x - sin(x);
plot(x,y1,x,y2,x,y3)
symlog(gca,'xy',-1.7)
  2 件のコメント
Qing-quan Zhi
Qing-quan Zhi 2016 年 6 月 29 日
Yeah, the bi-symmetric logarithmic axes is very useful way to display some data, although it is not really accurate in math. And you give a perfect solution! Thank you!
Jungmin kim
Jungmin kim 2023 年 6 月 2 日
I'm really grateful for your work. Your creations have significantly saved me time.

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

その他の回答 (2 件)

the cyclist
the cyclist 2016 年 6 月 28 日
This strikes me as an incorrect and potentially deceptive way to plot these data.
Instead, I think I would use the subplot function, putting the positive data in the upper subplot and the negative data into the lower subplot. Then, there would be a "chasm" between the two, which makes sense because they really are separated in log space.
Granted that by default the two plots would take up some real estate on the page, but you can adjust properties to minimize the impact of that.

Rajen Biswa
Rajen Biswa 2018 年 4 月 15 日
I have these data: Ebbyno=[ -5 -3 -1 1 3 5 7 9 11 13 15}; already in dB. BER1= [ 0.3993 0.3769 0.3445 0.3015 0.2091 0 0 0 0 0 0 0 0]; how can i use the loglog plot to plot this data in matlab.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by