1
$\begingroup$

I'm running into a strange issue with ListPlot.

I'm trying to plot some data with particular values for PlotRange, PlotLabels, and AspectRatio. However, if I enforce the desired values for PlotLabels and AspectRatio (as in plt1 below), Mathematica 12.2 is changing the output's PlotRange. Yet, if I enforce only one of PlotLabels or AspectRatio (as in plt2 or plt3 below), it returns the correct PlotRange. Is there a way to simultaneously specify all three correctly?

I've attached a minimal working example.

data = Table[{x, 1}, {x, -2., 2.}];
plt1 = ListPlot[
  data
  , PlotRange -> {{-2., 2.}, {0., Sqrt[2.]}}
  , PlotLabels -> "PlotLabels and AspectRatio"
  , AspectRatio -> .353553
  ]

PlotRange is incorrect

plt2 = 
 ListPlot[
  data
  , PlotRange -> {{-2., 2.}, {0., Sqrt[2.]}}
  , PlotLabels -> "PlotLabels"
  ]

The PlotRange is correct

plt3 = 
 ListPlot[
  data
  , PlotRange -> {{-2., 2.}, {0., Sqrt[2.]}}
  , AspectRatio -> .353553
  , PlotLabel -> "AspectRatio"
  ]

The PlotRange is correct

Thanks in advance!

$\endgroup$

1 Answer 1

1
$\begingroup$

PlotRangePadding is the option you are not controlling. Set it to None to get the control you seek.

data = Table[{x, 1}, {x, -2., 2.}];
plt1 = ListPlot[data, PlotRange -> {{-2., 2.}, {0., Sqrt[2.]}}, 
  PlotLabels -> "PlotLabels and AspectRatio", AspectRatio -> .353553, 
  PlotRangePadding -> None]

enter image description here

Set to larger values if desired (see docs).

$\endgroup$
1
  • $\begingroup$ Thanks for your quick reply! $\endgroup$ Apr 21, 2021 at 0:36

Your Answer

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

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