1
$\begingroup$

I have a graph obtained using ListPlot. What I plot goes between -1000 and +75.

I would like to construct a graph showing the whole range, with a scale such that what is between 0 and 100 takes about the same place as what is between -1000 and 0. To have something like that (for the vertical axis):

enter image description here

Would you have an idea I could use to avoid doing that "by hand"?

Thanks a lot.

$\endgroup$
7
  • $\begingroup$ What if you add PlotRange -> All? $\endgroup$ Commented Feb 3, 2021 at 14:00
  • $\begingroup$ "What I plot goes between -1000 and +75" are you referring to the horizontal or vertical scale here? Can you show an example with code and data? $\endgroup$
    – MarcoB
    Commented Feb 3, 2021 at 14:01
  • $\begingroup$ @J.M.: thanks a lot. I have included a figure to better illustrate what I want to do. $\endgroup$ Commented Feb 3, 2021 at 14:27
  • $\begingroup$ @MarcoB: thanks a lot. The range I was referring to was the vertical axis. I just added a figure I made to illustrate what I am trying to do. I hope it clarifies it. $\endgroup$ Commented Feb 3, 2021 at 14:29
  • 1
    $\begingroup$ @Laurent I think you might consider a log plot (e.g. ListLogPlot) after rescaling your data so it is no longer negative (e.g. by adding a positive constant to it?). I am also concerned that the readability of your proposed plot would be very poor: the reader's eye would be greatly deceived by your subtle and non-standard change in scale. $\endgroup$
    – MarcoB
    Commented Feb 3, 2021 at 15:33

1 Answer 1

1
$\begingroup$

Use the ScalingFunctions option

ClearAll["Global`*"]

SeedRandom[1234];

data = Table[{RandomReal[10], RandomReal[{-1000, 100}]}, {20}];

f = If[# > 0, 10 #, #] &;

ListPlot[data,
 PlotRange -> {-1000, 100},
 Ticks -> {Automatic, 
   Join[Range[0, 100, 20], Range[-1000, -200, 200]]},
 ScalingFunctions -> {None, {f, InverseFunction[f]}}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Great! Thank you so much for your help. This is perfect :-) $\endgroup$ Commented Feb 4, 2021 at 8:44
  • $\begingroup$ I have been trying to understand the code, and tried to make a few changes to it. How could I proceed if I wanted to keep the same scale for values of y = [- 100, 100] and the scale 1/10 for y = [-1000,-100] ? Thanks a lot. $\endgroup$ Commented Feb 4, 2021 at 9:59
  • $\begingroup$ Is f = If[# > -100, #, #/10] &; what you want? $\endgroup$
    – Bob Hanlon
    Commented Feb 4, 2021 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.