3
$\begingroup$

I need a way to get the absolute tick specifications in the form of list of position/label pairs, and have not been able to come up with a robust way.

For the following, I'll be using this test plot:

plt = Plot[x, {x, 0, 1}, Frame -> True, PlotRangePadding -> 0]

Mathematica graphics

Things I have tried so far include:

  • Specifying Charting`ScaledTicks[{Identity,Identity}]:

    Mathematica graphics

    Notice the missing 1.0 tick mark.

  • Using AbsoluteOptions:

    InputForm@PlotRange /. Quiet@AbsoluteOptions@plt
    (* {{0., 1.}, {0., 0.9999999795918367}} *)
    

    This probably also explains why the above fails.

  • PlotRange@plt, Charting`CommonDump`getplotrange@plt and GraphicsInformation@plt all fail similarly

  • FullGraphics is also completely broken
  • I tried to look at the GraphicsBox expression resulting from the plot, but the PlotRange is still wrong there and the FrameTicks have not yet been expanded.
  • I also tried to look at the definitions of Typeset`MakeBoxes, which appears to handle some of the option transformations for graphics, but I couldn't find anything, and they also seem to be unused during normal operation

Is there any way to replicate what the front end is doing? I guess it's just rounding the plot ranges before feeding them into whatever tick-making function it uses internally, but is there a way to tell what exactly is going on?

$\endgroup$
  • $\begingroup$ Not sure what happened there, but try this: tt = Charting`ScaledTicks[{Identity, Identity}][0, 3]; {Plot[2 x, {x, 0, 3}, Frame -> True, FrameTicks -> {None, {tt, None}}, PlotRangePadding -> 0], Plot[2 x, {x, 0, 3}, Frame -> True, FrameTicks -> {None, {Automatic, None}}, PlotRangePadding -> 0]} $\endgroup$ – J. M. will be back soon Mar 19 '18 at 3:15
  • $\begingroup$ @J.M. I'm aware that that will work - but I need a way to get the ticks for an arbitrary plot, where the plot range is not manually set to something nice. As I tried to explain in the question, the front-end seems to be doing some rounding, but if I want it to always work, I need to know what exactly is being done. $\endgroup$ – Lukas Lang Mar 19 '18 at 7:54
  • $\begingroup$ @LukasLang, just saw this question, maybe too late, but... You probably aware of Chartingget2DPlotRange[Plot[...]], this gives true plot ranges used by MMA to plot and to place ticks. So for your plt` it gives {{0.,1.},{0.,1.}}. Then ChartingScaledTicks[{Identity,Identity}][<here is plot range>]` replicate MMA ticks. $\endgroup$ – Alx Aug 20 at 7:06
  • $\begingroup$ @Alx Thanks for the suggestion, but unfortunately I can't seem to get it to work. If you look at Charting`get2DPlotRange@plt // InputForm, $1$ is still excluded from the vertical plot range. $\endgroup$ – Lukas Lang Aug 20 at 7:13
  • $\begingroup$ I tried this way: pr=Chartingget2DPlotRange[plt], then Plot[x, {x, 0, 1}, Frame -> True, PlotRangePadding -> 0, FrameTicks -> ChartingScaledTicks[{Identity, Identity}][Sequence @@ pr[[2]]]] and all 1s are presented. $\endgroup$ – Alx Aug 20 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.