Force scientific notation in tick marks of ListLogLogPlot

I am trying to set tick marks in a ListLogLogPlot. When searching for Mathgroup archives, it seems that the usual way to link to tick labels is to retrieve them using AbsoluteOptions , start the replacement rule in a custom format, and then directly connect to the charting function using the Ticks->{...} option. However, for ListLogLogPlot, the following does not work:

 foo = ListLogLogPlot[Range[20]^3, Frame -> True]; ticks=(FrameTicks /. AbsoluteOptions[foo, FrameTicks]) 

Any ideas on how to handle this? ..


Edit: there are a lot of good answers here! Accepting Mr. Master, as he was the shortest way to solve the immediate problem, but I see that I am using other methods proposed in the future.

+6
source share
5 answers

You can use substitutions to mess with 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, he is now improved and less fragile.

+6
source

Like Sjoerd, I usually prefer to write a function that computes 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]}}] 
+5
source

To complement the Brett answer , check out the CustomTicks package in LevelScheme . It provides two functions for creating LinTicks and LogTicks labels, and each of them has many formatting options. Currently, this requires performing the logarithm yourself, i.e.

 Plot[ {Log[10,Cosh[x]], Log[10, Sinh[x]]}, {x, 0, 4}, Frame -> True, FrameTicks -> { LinTicks, LogTicks, None, None }] 

gives

LogPlot of cosh and sinh over 0 to 4

For a list of data, obviously, you have to use Log[Base, data] with ListPlot , but it is functional. I introduced Mark Caprio patch so that the following is done the same as above

 LogPlot[ {Cosh[x], Sinh[x]}, {x, 0, 4}, Frame -> True, FrameTicks -> { LinTicks, LogTicks, None, None }] 

If the patch is accepted, the old LogTicks form will be available by setting the PlotType option to Linear , Logarithmic by default. The advantage of using CustomTicks is that other databases are lightweight.

code for and plot of Exp [-x ^ 2] from 0 to 3

and it automatically formats it as you want.

Change I would also like to note that CustomTicks loads on its own, separately from the rest of LevelScheme . And, since this is a small package, there is not much extra overhead.

+5
source

Looks like a mistake. A simple call to AbsoluteOptions[foo] gives error messages. Normal Options[foo] works fine.

+4
source

Send an email with this code to support@Wolfram.com. They will be able to tell you if there is a known best workaround.

0
source

Source: https://habr.com/ru/post/885937/


All Articles