13
$\begingroup$

When using ListLogLinearPlot the abscissa labels every other decade.

Is there a way to tell Mathematica to label each decade?

I need to use this inside Manipulate where the axes will scale according to the chosen variable.

enter image description here

Here is some example code of the kind I am using:

s[x_] := (10^-9) x^2; t[x_] := (10^-3) x^2; 
Manipulate[ ListLogLinearPlot[{ Table[{a s[T], T}, {T, 0, 1000}], 
 Table[{a t[T], T}, {T, 0, 1000}] }, 
 GridLines -> None, PlotStyle -> {Thickness[0.005]}, Joined -> True, 
 PlotRange -> Automatic], {a, 10^-8, 10^8}]
$\endgroup$

migrated from stackoverflow.com Mar 30 '12 at 18:56

This question came from our site for professional and enthusiast programmers.

  • $\begingroup$ Could you please give an example of code - best the one producing this graphics, or your manipulate. $\endgroup$ – Vitaliy Kaurov Mar 30 '12 at 20:04
  • 2
    $\begingroup$ Perhaps this could help, see CustomTicksGuide.pdf, p. 4. $\endgroup$ – partial81 Mar 30 '12 at 20:40
  • $\begingroup$ @VitaliyKaurov s[x_] := (10^-9) x^2; t[x_] := (10^-3) x^2; Manipulate[ ListLogLinearPlot[{ Table[{a s[T], T}, {T, 0, 1000}], Table[{a t[T], T}, {T, 0, 1000}] }, GridLines -> None, PlotStyle -> {Thickness[0.005]}, Joined -> True, PlotRange -> Automatic], {a, 10^-8, 10^8}] $\endgroup$ – CaptanFunkyFresh Mar 30 '12 at 21:29
11
$\begingroup$

You can create some custom ticks that work the way you want. There might be a better way than Superscript, but I couldn't work out how to get ScientificForm or NumberForm to just show the exponent rather than 1 x 10^4 etc.

myTicks = Table[{10^i, Superscript[10, i]}, {i, -20, 15}]

Notice I've changed the way the a variable enters into the Manipulate, as it will give you more chance to explore some of the lower-exponent values.

Manipulate[
 ListLogLinearPlot[{Table[{10^a s[T], T}, {T, 0, 1000}], 
   Table[{10^a t[T], T}, {T, 0, 1000}]}, GridLines -> None, 
  Ticks -> {myTicks, Automatic}, PlotStyle -> {Thickness[0.005]}, 
  Joined -> True, PlotRange -> Automatic], {a, -8, 8}]

enter image description here

$\endgroup$
  • $\begingroup$ ListLogLinearPlot[] uses Superscript[] too ... so it seems the way to go. $\endgroup$ – Dr. belisarius Mar 31 '12 at 15:35
  • $\begingroup$ Thanks @Verbeia, this works just fine. I am now trying to implement this into FrameTicks where the upper horizontal tick marks are shown but without the decade labels, but this isn't a major concern. $\endgroup$ – CaptanFunkyFresh Apr 2 '12 at 14:50
5
$\begingroup$

One can adapt this answer to a smilar question to define a number format as follows:

 exponentForm[num_?NumericQ] := 
 ToString@NumberForm[N@#1, ExponentFunction -> (# &), NumberFormat -> (#3 &)] &@num

Applied to a portion of Verbeia'a tick list, this function gives

enter image description here

You can use it to define custom ticks with exponent labels:

  myExpTicks = Table[{10^i, exponentForm[10^i]}, {i, -20, 15}];

And, finally use it in your Manipulate as

 Manipulate[
 ListLogLinearPlot[{Table[{10^a s[T], T}, {T, 0, 1000}], 
 Table[{10^a t[T], T}, {T, 0, 1000}]}, GridLines -> None, 
 Ticks -> {myExpTicks, Automatic}, PlotStyle -> {Thickness[0.005]}, 
 Joined -> True, PlotRange -> Automatic], {a, -8, 8}]

to get

enter image description here

$\endgroup$
5
$\begingroup$

You can create custom ticks and use ListPlot :

myTicks[lower_, upper_, step_] := Flatten[Module[{Local = #, LocalTicks}, 
 LocalTicks = Log[10, Range[10^(# - 1), 10^#, (10^# - 10^(# - 1))/(10 - 1)]]; 
 Join[{#, ""} & /@ Most[LocalTicks], {{Last[LocalTicks], Power[10, 
 ToString[Last[LocalTicks]]] }}]] & /@ Range[lower, upper, step], 1]

Manipulate[ListPlot[{Table[{Log[10, a s[T]], T}, {T, 0, 1000}], Table[{Log[10, 
 a t[T]], T}, {T, 0, 1000}]}, GridLines -> None, PlotStyle -> {Thickness[0.005]}, 
 Joined -> True, PlotRange -> Automatic, Ticks -> {myTicks[lower, upper, step],
  Automatic}, AxesOrigin -> {lower, 0}], {{lower, -20, "lower"}},
  {{upper, 10, "upper"}}, {{step, 1, "step"}}, Delimiter, {a, 10^-8, 10^8}]

customTicks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.