5
$\begingroup$

Is there any easy way to manually set only one side of the plot range and let the other one be set by either the automatic value or the max value (either option would be acceptable, which ever one is easier)? So I would like to specify something like

ListPlot[data,PlotRange->{Automatic,{1,max}}]

To alter the y plot range to {1,max value in data}. I know I can find this value max by hand for each plot, but since I use this kind of option often I would like to avoid having a separate line for this each time.

$\endgroup$

2 Answers 2

6
$\begingroup$

You can use PlotRange -> {Automatic, {1, All}}.

An example:

SeedRandom[1]
data = RandomReal[100, {100, 2}];
data = Append[data, {{500, 50}, {50, 500}}];

Row[{ListPlot[data,  ImageSize -> 300, 
    PlotLabel -> "PlotRange -> Automatic"], 
  ListPlot[data,  ImageSize -> 300, 
    PlotRange -> All, PlotLabel -> "PlotRange->All"]
  ListPlot[data,  ImageSize -> 300, 
    PlotRange -> {Automatic, {70, All}}, 
    PlotLabel -> "PlotRange -> {Automatic, {70, All}}"  ]}, 
 Spacer[20]]

enter image description here

This works in both directions. You can use PlotRange -> {Automatic, {All, 50}} to have the vertical plot range go from the minimum of data to 50:

ListPlot[data,  ImageSize -> 300, 
  PlotRange -> {Automatic, {All, 50}}, 
  PlotLabel->"PlotRange -> {Automatic, {All, 50}}"  ]

enter image description here

$\endgroup$
0
$\begingroup$
SeedRandom[1];
data = RandomReal[100, {100, 2}];
data = Append[data, {{500, 50}, {50, 500}}];

Even shorter you can specify the Y-axis PlotRange only.

ListPlot[data, PlotRange -> {0, 50}]

Mathematica graphics

The default for the X-axis is Automatic

$\endgroup$
1
  • $\begingroup$ Thanks, that is interesting too. By the way maybe ListPlot[data, PlotRange -> {All, 50}] would illustrate the point better since it answers the question how to alter just the upper or lower endpoint. $\endgroup$
    – Kvothe
    Commented Aug 30, 2019 at 15:36

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.