How can I plot negative value with log scale?

100 vues (au cours des 30 derniers jours)
Qing-quan Zhi
Qing-quan Zhi le 27 Juin 2016
Commenté : Jungmin kim le 2 Juin 2023
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 commentaires
Qing-quan Zhi
Qing-quan Zhi le 28 Juin 2016
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 le 28 Juin 2016
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???

Connectez-vous pour commenter.

Réponse acceptée

Robert
Robert le 28 Juin 2016
Modifié(e) : Robert le 28 Juin 2016
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 commentaires
Qing-quan Zhi
Qing-quan Zhi le 29 Juin 2016
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 le 2 Juin 2023
I'm really grateful for your work. Your creations have significantly saved me time.

Connectez-vous pour commenter.

Plus de réponses (2)

the cyclist
the cyclist le 28 Juin 2016
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 le 15 Avr 2018
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.

Catégories

En savoir plus sur Log Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by