4
$\begingroup$

When labeling FrameTicks with my own labels, I stumbled upon a very curious behavior. If I label just one tick, it renders perfectly:

Plot[x, {x, 0, 1}, Frame -> {True, True, False, False}, 
      FrameTicks -> {{{0, "Low"}, 1}, Automatic}]

enter image description here

But if I want to specify both label names, it fails:

Plot[x, {x, 0, 1}, Frame -> {True, True, False, False}, 
      FrameTicks -> {{{0, "Low"}, {1, "High"}}, Automatic}] 

"A tick position in the value of the Ticks option should be a number."

However, if I specify 3 or more labels, it all goes back to normal.

Plot[x, {x, 0, 1}, Frame -> {True, True, False, False}, 
      FrameTicks -> {{{0, "Low"}, {0.5, "Medium"}, {1, "High"}}, Automatic}]

I can fix it of course by doing:

Plot[x, {x, 0, 1}, Frame -> {True, True, False, False}, 
      FrameTicks -> {{{0, "Low"}, {0.5, ""}, {1, "High"}}, Automatic}]

enter image description here

But this is not an elegant solution. Is that a bug or there is a reason for that?

$\endgroup$
6
$\begingroup$

This is a bit confusing. In older versions of Mathematica, the syntax for FrameTicks (and for Frame) was:

FrameTicks -> {bottom, left, top, right}

The new syntax is

FrameTicks -> {{left, right}, {bottom, top}}

For legacy reasons, the old syntax for FrameTicks is still supported. So, this is why your Frame specification shows the bottom and left frames. On the other hand, while the FrameTicks specification for your 1-label example matches the old syntax, the 2-label example matches the new syntax (with malformed ticks), and then the 3-label example again only matches the old syntax.

It would probably be good to get used to the new syntax and use it consistently. For the two label example it would be:

Plot[x, {x, 0, 1}, Frame -> {{True, False}, {True, False}}, 
    FrameTicks -> {{Automatic, None}, {{{0, "Low"}, {1, "High"}}, None}}]

enter image description here

$\endgroup$
  • $\begingroup$ Just beat me to the punch, was just making image ;). $\endgroup$ – Feyre Jan 27 '17 at 21:09
  • $\begingroup$ Awesome! This explains it very nicely! $\endgroup$ – Stitch Jan 27 '17 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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