# 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.

• Modified Mr. Wizard's code slightly, here - seems to as you wish – Jason B. Apr 15 '16 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 '16 at 9:59
• Thanks a lot @JasonB. I didn't remove the ticks[] 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 '16 at 10:06
• Never mind... Got it by adding Style[xlabels, ...] in the show function. Thanks – Selva Apr 15 '16 at 11:37

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 = Chartingget2DPlotRange@plot;
{ypos, xpos} = Last /@ range/17;

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

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

flipNegativeTicks@Plot[Sinc[x/10000], {x, -50000, 70000}] • This is really helpful. I am beginner here, can you please help me to get tick labels as -10.0, 10.0, 20.0 etc in place -10. , 10. , 20. – souravc Oct 25 '17 at 11:20
• @souravc - do you want to do that while also using the trick from this post, or just as a separate issue? – Jason B. Oct 25 '17 at 13:29
• yes, when I am using the trick described in the above post I want to get tick labels as -10.0, 10.0, 20.0 etc in place -10. , 10. , 20. Should I ask a separate question? – souravc Oct 25 '17 at 13:40
• @souravc - if you take the trick here, add the line ticks = ticks /. {a_, b_?NumericQ, c__} :> {a, NumberForm[SetPrecision[b, 4], 3], c}; after the line where ticks is defined, then the very first example plot here will do what you are looking for. This isn't versatile though, since for the second example it spits out an error because the NumberForm doesn't give enough zeros. – Jason B. Oct 25 '17 at 13:53
• Thanks a lot. It is working for me. I will keep in mind the probable loopholes. – souravc Oct 25 '17 at 14:05

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}]
Manipulate[
Plot[Sin[x], {x, -6, 6},
Ticks -> {tf[-6]~Join~tf, tf[-3]~Join~tf},
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}] 