1
$\begingroup$

When making a plot, sometimes I would like to alter the ticks and labeling of the ticks, in particular when doing a LogPlot or LogLogPlot.

Here an Example:

ticks = Automatic;

LogPlot[2/(3 Exp[3 x/2]), {x, 0, 40}, AxesOrigin -> {0, 1}, Ticks -> ticks]

There are a number of things I would like to change here.

(1) The x-Axis is now on top of the plot, so it would make more sense, and in many situation look better, to have the ticks below the axis, and the labeling {10,20,30,40} above. How can I do that?

(2) On the logarythmic y-Axis, I would like the main ticks to go in steps of 10^-3, rather than 10^-5. So from top to bottom I would like the labels to be {1,10^-3,10^-6,10^-9}, and between I would like to have small ticks without a label in steps of 10.

Now for two I actually know a way to do it, namely brute force specify the ticks manually like this:

ticks = {Automatic,
     {
      {10^-27, , {.008, 0}},
      {10^-26, , {.003, 0}}, {10^-25, , {.003, 0}},
      {10^-24, "10^-24", {.008, 0}},
      {10^-23, , {.003, 0}}, {10^-22, , {.003, 0}},
      {10^-21, , {.008, 0}},
      {10^-20, , {.003, 0}}, {10^-19, , {.003, 0}},
      {10^-18, "10^-18", {.008, 0}},
      {10^-17, , {.003, 0}}, {10^-16, , {.003, 0}},
      {10^-15, , {.008, 0}},
      {10^-14, , {.003, 0}}, {10^-13, , {.003, 0}},
      {10^-12, "10^-12", {.008, 0}},
      {10^-11, , {.003, 0}}, {10^-10, , {.003, 0}},
      {10^-9, , {.008, 0}},
      {10^-8, , {.003, 0}}, {10^-7, , {.003, 0}},
      {10^-6,"10^-6", {.008, 0}},
      {10^-5, , {.003, 0}}, {10^-4, , {.003, 0}},
      {10^-3, , {.008, 0}},
      {10^-2, , {.003, 0}}, {10^-1, , {.003, 0}},
      {1, 1, {.008, 0}
     }
    };

However this is extremely cumbersome, and I am wondering if there isn't an easier way to do it. Is there not a simple command that lets me specify the major ticks in steps of A, and the minor ticks in steps of B?

(3) Suppose I was satisfied with the default ticks that Mathematica makes for my plot. Then is there a way to manually add a tick and label at a special value, or I then have to manually specify all the ticks?

In the above example, for instance, could I add a single tick at x = 10.2, and specify a length of the tickmark, and position of its label? I know I could possibly do this by manually drawing a Graphics[Line[…]], however it would be a fiddling around to make it look good, adjusting the grayscale and thickness of the line. In the case of logarithmic plots, adjusting the position could also be cumbersome.

$\endgroup$
2

1 Answer 1

4
$\begingroup$

I will just answer the first question. You can use Frame/FrameTicks instead:

Show[
    LogPlot[
        2/(3 Exp[3 x/2]),
        {x,0,40},
        Frame->{{True,False},{False,True}}
    ],
    FrameTicks -> {{Charting`ScaledTicks["Log"], None}, {None, All}}
]

enter image description here

I used Show to add the actual ticks because handling of ticks inside of LogPlot seems to be suboptimal.

$\endgroup$
3
  • $\begingroup$ Nice approach! It however has the downside, that it also moves the y-axis slightly left of x=0, and the x-axis slightly above y=1. But apart from that, nice! Thanks! $\endgroup$
    – Britzel
    Jun 14, 2019 at 16:04
  • 1
    $\begingroup$ @Britzel You can incude PlotRangePadding->0 to the LogPlot to avoid the shift. $\endgroup$
    – Carl Woll
    Jun 14, 2019 at 16:54
  • $\begingroup$ Very good! Thanks again! $\endgroup$
    – Britzel
    Jun 14, 2019 at 21:45

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.