Mathematica flip the axes ticks (negative values) to other side

I have a plot as shown,

I want to change the axes ticks of the negative values as shown below,

I went through this post and with this answer, I am able to do only for Y-axis. Can someone please let me know how can I do this for both axes?.

Note: I also tried the comments from this answer for X-axis but that approach is not working.

If there is any other simple ways, please let me know.

Thanks in advance 🙂




Modified Mr. Wizard’s code slightly, here – seems to as you wish
– JasonB
Apr 15 at 9:58



Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Michael E2
Apr 15 at 9:59



Thanks a lot @JasonB. I didn’t remove the ticks[[1]] in show function and that caused all the issues. Again thanks a lot. One more thing, If I do this, the font style between negative and positive ticks are different. Any idea how to fix that?
– Selva
Apr 15 at 10:06



Never mind… Got it by adding Style[xlabels, …] in the show function. Thanks
– Selva
Apr 15 at 11:37


2 Answers


So this isn’t as robust as I would like, but it works decently on many test cases. I wish there was a way of extracting the automatic tick placement so that you could just reverse it,

flipNegativeTicks[plot_] :=
Module[{ticks, xticks, yticks, xlabels, ylabels, xpos, ypos, range},
ticks = Ticks /. AbsoluteOptions[plot];
range = Charting`get2DPlotRange@plot;
{ypos, xpos} = Last /@ range/17;

{yticks, ylabels} =
Replace[ticks[[2]], {a_?Negative, b_, c_, x__} :> {a,
Sow@Text[b, {ypos, a}];, -c, x}, 1] // Reap;
{xticks, xlabels} =
Replace[ticks[[1]], {a_?Negative, b_, c_, x__} :> {a,
Sow@Text[b, {a, xpos}];, -c, x}, 1] // Reap;
Show[plot, Graphics[{xlabels, ylabels}], Ticks -> {xticks, yticks},
PlotRange -> Charting`get2DPlotRange@plot]

flipNegativeTicks@Plot[40 Sin[x/20], {x, -10, 70}]

flipNegativeTicks@Plot[Sinc[x/10000], {x, -50000, 70000}]

This is a motivating post. I’m sure others could do much better and I have not refined it (no time):

tf[n_?Positive] := Table[{j, j, {0.02, 0.02}}, {j, 1, n}]
tf[n_] := Table[{j, “”, {0.02, 0.02}}, {j, n, -1}]
txth[{l_, u_}, p_, col_] :=
Text[Style[#, col], {#, p}] & /@ Range[l, u]
txtv[{l_, u_}, p_, col_] :=
Text[Style[#, col], {p, #}] & /@ Range[l, u]
gl[{l_, u_}, s_] :=
Table[{j, {Gray, Thick}}, {j, l, u}]~Join~
Table[{j, LightGray}, {j, l, u, s}]
Plot[Sin[x], {x, -6, 6},
Ticks -> {tf[-6]~Join~tf[6], tf[-3]~Join~tf[3]},
Epilog -> {txth[{-6, -1}, p, Red]~Join~txtv[{-3, -1}, p, Red]},
GridLines -> {gl[{-6, 6}, 0.2], gl[{-4, 4}, 0.2]},
AspectRatio -> Automatic, PlotRange -> {-4, 4}], {p, 0.1, 0.5}]