Extract ticks from plot
You can try to build the automatic ticks manually using the undocumented internal function Charting`FindTicks
.
plot = Plot[Sin[x], {x, 0, 20}];
Charting`FindTicks[{0, 1}, {0, 1}] @@ PlotRange[plot][[1]]
{{0., 0}, {5., 5}, {10., 10}, {15., 15}, {20., 20}, {0., "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, {1., "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, {2., "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, . . . }
Note that PlotRange[plot]
returns the plot range, also undocumented.
Based on the comment of @grbl , there is indeed a workaround to get automatic plot ticks that can be read out using AbsoluteOptions
by using CustomTicks
. It requires very little extra coding:
plot = Plot[Sin[x], {x, 0, 20}, Ticks -> LinTicks]
xticks = First[Ticks /. First[AbsoluteOptions[plot, Ticks]]]
(*
{{0., " 0", {0.04, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {5.,
" 5", {0.04, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {10.,
"10", {0.04, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {15.,
"15", {0.04, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {20.,
"20", {0.04, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {1.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {2.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {3.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {4.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {6.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {7.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {8.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {9.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {11.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {12.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {13.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {14.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {16.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {17.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {18.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}, {19.,
"", {0.015, 0.}, {GrayLevel[0.], AbsoluteThickness[2.]}}}
*)