I am trying to custom-format tick labels on a ListLogLogPlot. By searching Mathgroup archives, it looks like the usual way to mess with tick labels is to extract them using AbsoluteOptions
, run a replacement rule with the custom format, and then explicitly feed them to the plotting function with the Ticks->{...}
option. However, the following doesn't work for ListLogLogPlot:
foo = ListLogLogPlot[Range[20]^3, Frame -> True];
ticks=(FrameTicks /. AbsoluteOptions[foo, FrameTicks])
Any ideas on how to deal with this?..
Edit: lots of good answers here! Accepting Mr. Wizard's since it proved to be the most concise way to solve the immediate problem at hand, but I see myself using the other methods suggested in the future.
One can use replacements to mess with the labels directly, bypassing Option
/AbsoluteOptions
:
ListLogLogPlot[Range[20]^3, Frame -> True] /.
(FrameTicks -> x_) :>
(FrameTicks -> (x /. {a_?NumericQ, b_Integer, s___} :>
{a, Superscript[10, Log10@b], s} ))
Thanks to Alexey Popkov this is now improved and less fragile.
Like Sjoerd, I generally prefer to write a function that computes the ticks on the fly:
PowerTicks[label_][min_, max_] := Block[{min10, max10},
min10 = Floor[Log10[min]];
max10 = Ceiling[Log10[max]];
Join[Table[{10^i,
If[label, Superscript[10, i], Spacer[{0, 0}]]}, {i, min10,
max10}],
Flatten[
Table[{k 10^i,
Spacer[{0, 0}], {0.005, 0.`}, {Thickness[0.001`]}}, {i, min10,
max10}, {k, 9}], 1]]
]
ListLogLogPlot[Range[20]^3, Frame -> True,
FrameTicks -> {{PowerTicks[True],
PowerTicks[False]}, {PowerTicks[True], PowerTicks[False]}}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With