1
$\begingroup$

I have LogLinear plots for which I want to scale the ticks on the x-axis. The following MWE, which works for the linear plot is showing ticks at the wrong positions for the LogLinear plot

Clear[plot];

plot = LogLinearPlot[Erf[x], {x, 1, 100}]
scalefact= 10^(-10);
newticks = {#, scalefact #} & /@ Range[1, 100];
Show[plot, Ticks -> {newticks, Automatic}]

plot1

plot2

Since I already have the plots I would not like to scale the x-axis, I just want to change the tick specifications. Thanks.

$\endgroup$

2 Answers 2

1
$\begingroup$

You can take x-Ticks from plot either with:

oldticks = Charting`ScaledTicks[{Log, Exp}][Log@1, Log@100, {6,6}]

or with:

oldticks = (Ticks /. AbsoluteOptions[plot, Ticks])[[1]]

Now change labels:

Show[plot, 
 Ticks -> {oldticks /. {a_?NumericQ, b_?NumericQ, c__} :> {a, scalefact b, c}, 
  Automatic}]

enter image description here

EDIT

To answer new request in comment about having only specific ticks:

newTicks = {Log[#], scalefact #} & /@ {1., 10., 100.}
newTicksEmpty = {Log[#], Spacer[0]} & /@ {1., 10., 100.}
Show[plot, 
 FrameTicks -> {{Automatic, Automatic}, {newTicks, newTicksEmpty}}, 
  Frame -> True]

enter image description here

Minor ticks can be added with Subdivide of the corresponding interval and using technique as for newTicksEmpty:

minor = {Log@#, Spacer[0], {0.005, 0}} & /@ 
 Join[Subdivide[1, 10., 9], Subdivide[10, 100., 9]]

Show[plot, 
 FrameTicks -> {{Automatic, Automatic}, {Join[newTicks, minor], 
    Join[newTicksEmpty, minor]}}, Frame -> True]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks for the answer. The Charting`ScaledTIcks works for me. Just another related query. How do I control the positioning of the major and minor ticks. For instance, in the above example I want the ticks to appear only at 10^(-10), 10^(-9) and 10^(-8). $\endgroup$
    – smj
    Nov 27, 2019 at 9:46
  • $\begingroup$ Please, see my edit. $\endgroup$
    – Alx
    Nov 27, 2019 at 12:13
  • $\begingroup$ This is exactly what I wanted. Thank you once again. $\endgroup$
    – smj
    Nov 27, 2019 at 12:37
  • $\begingroup$ Glad to help you. $\endgroup$
    – Alx
    Nov 27, 2019 at 13:15
0
$\begingroup$

Try this:

newticks = Map[{#, # *1.*10^-10} &, Range[1, 100]];

which only differs from your definition by a factor 1..

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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