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 个评论
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
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 个评论
Jungmin kim
2023-6-2
I'm really grateful for your work. Your creations have significantly saved me time.
更多回答(2 个)
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.
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!