1
$\begingroup$

I wanted to make a plot with custom frame ticks. For example, lets say I want to make a plot

 ListPlot[{{1.1,3.9},{2.9,3.1}},
   Axes->None,Frame->{{True,False},{True,False}},PlotRange->{{1,3},{3,4}}
 ]

but I want to change the frame ticks so that only 1, 2, and 3 show up on the x-axis, and there are only ticks at 3 and 4 on the y-axis and these ticks say "low" and "hi" respectively.

In the documentation for frameticks it gives the example

Plot[Sin[x], {x, 0, 10},
  Frame -> True, 
  FrameTicks -> {{{0, 0 \[Degree]}, {Pi, 180 \[Degree]}, {2 Pi,  360 \[Degree]}, {3 Pi, 540 \[Degree]}}, {-1/2, 1/2}}
]

This is also the pattern suggested in this answer.

Following this pattern, it seems I should try

ListPlot[{{1.1,3.9},{2.9,3.1}},
  Axes->None,Frame->{{True,False},{True,False}},PlotRange->{{1,3},{3,4}},
  FrameTicks->{{1,2,3},{{3,"low"},{4,"high"}}}
]

however, this produces an error. I have also tried

Show[
  ListPlot[{{1.1,3.9},{2.9,3.1}},
    Axes->None,Frame->{{True,False},{True,False}},PlotRange->{{1,3},{3,4}}
  ],
  FrameTicks->{{1,2,3},{{3,"low"},{4,"high"}}}
]

but this also produces an error. Somehow putting FrameTicks in quotes in the previous line fixes the error:

Show[
  ListPlot[{{1.1,3.9},{2.9,3.1}},
    Axes->None,Frame->{{True,False},{True,False}},PlotRange->{{1,3},{3,4}}
  ],
  "FrameTicks"->{{1,2,3},{{3,"low"},{4,"high"}}}
]

But I feel like I am doing this wrong way. Is there a better way to do this?

$\endgroup$
3
$\begingroup$

Yes, do

ListPlot[{{1.1,3.9},{2.9,3.1}},
  Axes->None,Frame->{{True,False},{True,False}},PlotRange->{{1,3},{3,4}},
  FrameTicks->{{{{3,"3.0"},{4,"4.0"}},None},{{1,2,3},None}}
]

As stated in the documentation for FrameTicks, FrameTicks expects the option value to be in the form {{left, right}, {top, bottom}}, and if it doesn't think you gave an option value in that form, it will look for the form {x, y}. Since your {{3, "low"}, {4, "high"}} list has length two, it gets confused and thinks you are trying to give it an option value in the form {{left, right}, {top, bottom}}. To avoid this, just explicitly put your FrameTicks option value in the preferred form.

Note that if you had put three ticks on the y-axis (FrameTicks -> {{1, 2, 3}, {{3, "low"}, {3.5, "medium"}, {4, "high"}}}) it would have worked, since now the y ticks does not have length 2 so Mathematica does not get confused about whether you are using the {{left, right}, {bottom, top}} form or the {x, y} form.

$\endgroup$

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.