I'm making the ticks labels of my plot using the rule:
FrameTicks -> {{N@FindDivisions[{Min@data1, Max@data2}, 6], None},
{Range[1960, 2015, 10], None}}
This is generating the ticks I want on both axes pretty well. The only problem is that the y-axis ticks vary in the number of decimal places, which I do not want. Is there a way to make all those numbers have the same number of decimal places as the one with the most decimal places?
I wanted to use something like NumberForm[ticks, {∞, n}]
with ticks
being the N@..., 6]
above, but I'm not sure what n
should be to just go with the tick mark with the most decimal places.
Thank you!
Answer
First, generate the ticks and their labels with whatever range is desired.
ticks[min_, max_] := Module[{d = FindDivisions[{min, max}, 6], n},
n = Ceiling@Log10@Max@Denominator@d; {#, NumberForm[#, {∞, n}]} & /@ N@d]
For instance,
t = ticks[.01,.03]
(* {{0.01, NumberForm[0.01, {∞, 3}]}, {0.015, NumberForm[0.015, {∞, 3}]},
{0.02, NumberForm[0.02, {∞, 3}]}, {0.025, NumberForm[0.025, {∞, 3}]},
{0.03, NumberForm[0.03, {∞, 3}]}} *)
(The Output
actually looks like .)
They can then be used as, for instance,
Plot[x, {x, 0, .04}, Ticks -> {Automatic, t}, AspectRatio -> 1]
Comments
Post a Comment