Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force scientific notation in tick labels of ListLogLogPlot

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.

like image 303
Leo Alekseyev Avatar asked Apr 14 '11 20:04

Leo Alekseyev


2 Answers

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} ))

enter image description here


Thanks to Alexey Popkov this is now improved and less fragile.

like image 149
Mr.Wizard Avatar answered Nov 09 '22 06:11

Mr.Wizard


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]}}]
like image 28
Brett Champion Avatar answered Nov 09 '22 04:11

Brett Champion