3

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?

Lukas Lang
  • 33,963
  • 1
  • 51
  • 97
  • 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]} – J. M.'s missing motivation Mar 19 '18 at 03:15
  • @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. – Lukas Lang Mar 19 '18 at 07:54
  • @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 yourpltit gives{{0.,1.},{0.,1.}}. ThenChartingScaledTicks[{Identity,Identity}][<here is plot range>] replicate MMA ticks. – Alx Aug 20 '19 at 07:06
  • @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. – Lukas Lang Aug 20 '19 at 07:13
  • 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. – Alx Aug 20 '19 at 07:50
  • @LukasLang, some weird behavior of ChartingscaledTicks. As I wrote in previous comment,FrameTicksoption with plot range fromget2DPlotRangegives desired result, but the same ChartingScaledTicks[{Identity,Identity}][Sequence@@pr[[2]]] alone doesn't include 1. It is strange because underlying N@FindDivisions[pr[[2]],{6,6}] includes 1. And the full form Charting`ScaledTicks["Linear", {Identity, Identity}, "Nice"][Sequence @@ pr[[2]]] also shows 1. – Alx Aug 20 '19 at 09:20
  • @Alx Sorry for coming back to you so late - I think I finally figured out why your code is "working": The plot you show with the explicit ticks produces the correct result because Plot silently (for some reason) discards the invalid FrameTicks specification and uses the default. If you specify FrameTicks->{Automatic, Charting`ScaledTicks[…][…]}, it gives the wrong result as expected. And for the other part: It looks like FindDivisions is not used for that particular ScaledTicks call, only for the "Nice" version, which probably explains why that one works – Lukas Lang Sep 17 '19 at 20:17
  • @LukasLang, well, you are right with your example of semi-Automatic FrameTicks. But this can be fixed either by removing PlotRangePadding -> 0 option, or adding PlotRange -> pr, where pr = Charting``get2DPlotRange[plt]. This works for my needs (I use this when I need custom ticks), but I have no such experience in MMA as you have and this may work just by a fluke. – Alx Sep 18 '19 at 00:43

0 Answers0