How can I plot negative value with log scale?

205 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by