5
$\begingroup$

I'm noticing that using Callout seems to override the PlotRange option of Plot, increasing it a little bit. As an MWE:

Plot[
 x^2,
 {x, 0, 2}, PlotRange -> {{0, 2}, {0, 6}}
 ]

produces the desired plot with the desired range

enter image description here

but

Plot[
 Callout[x^2, "\!\(\*SuperscriptBox[\(x\), \(2\)]\)", {0.8, 2.0}, 1.0],
 {x, 0, 2}, PlotRange -> {{0, 2}, {0, 6}}
 ]

Increases the plot range slightly to about {{0,2.05}, {0,6.5}}, even though the callout label is well within the original bounds.

enter image description here

There is a similar question here, "Plot extends beyond given range", but their function and solution seem much more involved than I feel should be available.

Thank you for any thoughts.

$\endgroup$
4
  • $\begingroup$ It seems like a bug. $\endgroup$ Feb 13 at 21:29
  • 2
    $\begingroup$ Try adding the PlotRangePadding -> None option. $\endgroup$
    – creidhne
    Feb 13 at 21:30
  • 3
    $\begingroup$ @creidhne thank you! I found that the plotted function was continuing to be plotted beyond the desired range, even when setting PlotRangeClipping->True in the original Plot call, but saving the over-extended plot to plt and re-stating it by Show[plt, PlotRangeClipping->True] fixed that. (This happened to be easier in my actual case than just trimming the plotting bounds, so thought I'd mention it.) $\endgroup$
    – user241891
    Feb 13 at 21:45
  • $\begingroup$ @user241891 turn your comment into a self answer! That may be interest For the next reader $\endgroup$
    – MarcoB
    Feb 14 at 11:31

1 Answer 1

2
$\begingroup$

At @MarcoB's suggestion, I'm summarizing the relevant resolutions here.

@creidhne swoops in with the definitive fix to just add PlotRangePadding -> None to the Plot options. This worked beautifully for the axes, but did not restrict the domain on which the function was actually being plotted. This isn't really an issue in my MWE, but my actual problem was a ListPlot which had nonuniformly distributed data which I didn't want to plot beyond a particular value, so just specifying the PlotRange didn't fix the issue.

I found that setting PlotRangeClipping -> True in Plot did not fix this, but saving the plot ( plt = Plot[...] ) and then reasserting the options with Show[plt, PlotRangeClipping->True] did the trick.

$\endgroup$
1
  • $\begingroup$ Thank you! (+1) $\endgroup$
    – MarcoB
    Feb 28 at 17:04

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.