Clear Filters
Clear Filters

How can I plot loglog(x,y) with experimental data including negative and less than one

3 views (last 30 days)
I tried to plot a big set of experimental data which in 'x' axis ranges from negative data to positive, and also includes data less and more than 1.0. if I use loglog(abs(x),y) , obviously it draws both negative and positive 'x' values in one side, but I want to keep sign of 'x' values while converting to log scale. Also tried to define xlog = sign(x).*log10(abs(x)); but problem didn't solve, it is not like loglog. Any comments please how to do that?? Thanks

Accepted Answer

Michael Haderlein
Michael Haderlein on 24 Apr 2015
Why do you want a logarithmic plot of this data? Usually, when using loglog (or semilog) the point is that a change from, let's say, 1e-5 to 1e-4 is about as important for understanding as a change from 10 to 100. So, relative changes matter rather than absolute changes. However, relative changes don't change the sign.
I remember once there was a similar issue, we did want to pronounce relative changes, but some data sets were positive and others were negative (no change in sign within one set). We then used abs(data) to allow for the logscale, but applied different line styles/colors to emphasize the different signs. Honestly, it's ok but not too intuitive.
  1 Comment
Ray on 24 Apr 2015
Yes this is valid for my data on 'y' axis which range from 1e-5 to 1e6 , but my data on 'x' axis change from, lets say -100 to 100 with very small increments which covers -1<x<1. Obviously I don't want to see 'y' data for x = -100 and x = 100 at same place.

Sign in to comment.

More Answers (2)

MD on 24 Apr 2015
There is no side (as a reference to zero) on a log scale. You can try separating your x into negatives and positives. And then plot log of absolute values on two separate graphs.
xPositive = x(x>0);
yPositive = y(x>0);
xNegative = abs( x(x<0) );
yNegative = y(x<0);
semilogx(xPositive, yPositive);
semilogx(xNegative, yNegative);

Ray on 24 Apr 2015
The data set on 'y' axis in loglog scale ranges from 1e-5 to 1e6, which is fine since all are positive,,, but the data on 'x' axis range from -100 to 100 with very small increments. Obviously I don't want to see 'y' data for x = -100 and x = 100 at the same place. Solution which comes to mind is to convert data for 'x' axis to loglog for two different region x>0 and x<0 , and then for x<0 do (-1)*loglog(abs(x)) and insert both set to a single vector,,, then finding loglog(y) vector,,, and at the end just 'plot' this two new x , y data set. I am trying to find loglog data for x and y data set without drawing it... as you know loglog is different from log10(abs(x)),,, it looks something like: x = 10^round(log10(x) + 0.5)
Any comments how to do this? Thanks

Community Treasure Hunt

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

Start Hunting!