Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to position ticklabels on negative $y$ axis on its right side? Ticklabels on positive $y$ axis should remain as usual:

enter image description here

share|improve this question
Related: – Mr.Wizard Jun 4 '12 at 10:14
@Mr.Wizard: These are Input/Output characteristics of scalar quantization. When these diagrams are small, the lebels and the curves tend to overlap! – Bhaskar Dey Jun 4 '12 at 10:16

Here's one idea. Notice that the tick-marks are flipped as well.

p = Plot[Round[x], {x, -5, 5}, Exclusions -> None, PlotStyle -> Thick];

ticks = Ticks /. AbsoluteOptions[p];

{yticks, labels} =
     {a_?Negative, b_, c_, x__} :> {a, Sow@Text[b, {0.3, a}];, -c, x},
   ] // Reap;

Show[p, Graphics[labels], Ticks -> {ticks[[1]], yticks}]

Mathematica graphics

share|improve this answer
What about the x axis? – Ajasja Jun 4 '12 at 11:43
+1 Nice idea! Why do + and - minor $y$-ticks have different lengths? And why does the $y$-tick at +3.5 seem longer than the one at +3.0? Are these rasterization artefacts? – István Zachar Jun 4 '12 at 11:53
@István thanks. I believe it is a rasterization artifact as it appears even at large sizes. – Mr.Wizard Jun 4 '12 at 12:01
@Ajasja the OP asked for the y axis modification. You could do the same thing for only x (ticks[[2]] -> ticks[[1]] & {0.3, a} -> {a, 0.3}) or for both in two steps. – Mr.Wizard Jun 4 '12 at 12:29
Ahh, sorry, sloppy reading, I was just looking at the example image. +1. – Ajasja Jun 4 '12 at 12:33

Lots of magic numbers, no real scalability and rather specific solution for the given case, but it shows how you can build your own tick function easily from scratch. Since I don't think there is any way to finetune the Axes/AxesStyle/Frame options to suit your needs, this is the best I could suggest at the moment. Or you might want to use David Park's Presentations` package or the CustomTicks` package by Mark Caprio to specify aesthetic tick positions for any range (thanks Szabolcs).

{minX, maxX} = {minY, maxY} = {-5, 5}; (* range *)
{xO, yO} = {0, 0}; (* origo *)
d = .2; (* tick length *)
step = 1; (* tick step *)
offset = 1.5; (* tick label offset *)

Plot[IntegerPart@x, {x, minX, maxX}, Exclusions -> None, 
 PlotStyle -> {Black, Thick}, AspectRatio -> 1, 
 PlotRange -> {{minX, maxX}, {minY, maxY}}, Axes -> False, 
 Epilog -> {
   Black, Line[{{minX, yO}, {maxX, yO}}], Line[{{xO, minY}, {xO, maxY}}],
     Line@{{i, yO}, {i, yO + d}},
     Text[i, {i, yO + d}, {0, -offset}]
     }, {i, minX, xO - 1, step}],(* -x *)
     Line@{{i, yO}, {i, yO - d}},
     Text[i, {i, yO - d}, {0, offset}]
     }, {i, xO + 1, maxX, step}],(* +x *)
     Line@{{xO, i}, {xO + d, i}},
     Text[i, {xO + d, i}, {-offset, 0}]
     }, {i, minY, yO - 1, step}],(* -y *)
     Line@{{xO, i}, {xO - d, i}},
     Text[i, {xO - d, i}, {offset, 0}]
     }, {i, yO + 1, maxY, step}] (* +y *)
   }, PlotRangePadding -> Scaled@.05]

Mathematica graphics

share|improve this answer
You could use the CustomTicks package to generate tick positions, it'd make the solution a little easier to modify/reuse. – Szabolcs Jun 4 '12 at 10:47
@Szabolcs: I never used that package, but it seems very useful. Actually, I think it worths its own answer, and would be a perfect starting point for people willing to learn how to use it! So if you have any knowledge, please post your CustomTicks-based solution! – István Zachar Jun 4 '12 at 10:55
@Szabolcs I agree, your suggestion would make a good answer on it's own. – Ajasja Jun 4 '12 at 11:43

This needs some tweaking, but could be a starting point for a more general solution. The idea is to plot the bottom left quadrant of the plot with a Frame top and right, and the top right quadrant of the plot with a Frame bottom and left. Then Inset those into the complete plot.



enter image description here

Clearly there is a problem with all the ticks at the origin, and the insets had to be scaled by trial and error, but there might be a way to automate that.

share|improve this answer
Devious workaround. – István Zachar Jun 4 '12 at 11:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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