4
$\begingroup$

I am attempting to annotate a graph in a very simple manner. This is 2D plot of a function over a range of x-values, for example, let's say 0 to 15. By default, my plot labels the Tick marks as 0, 5, 10, 15, ...

What I would like to do is at the value of 10 on the x-axes (in this simple example) add the additional label of "L" (for example, a single letter) to the Tick Mark at the value of 10.

I have been experimenting and reading up on the documentation and I find no way to do this so far.

$\endgroup$
2
  • 1
    $\begingroup$ Have you looked up Ticks in the documentation? $\endgroup$ Commented Nov 11, 2015 at 11:54
  • $\begingroup$ @Edmund -- sure I have but I tried lots of variations and they all seem to want a number as a tick mark label. I want the label to be nothing other than the letter L which is not a number. $\endgroup$ Commented Nov 12, 2015 at 6:36

2 Answers 2

2
$\begingroup$

As mentioned in my comment above you need to look at the Ticks option of Plot. There you will see that you can use labels for the tick markers. In the Details section look at the 4th form $\left\{\left\{x_1,\text{label}_1\right\},\left\{x_2,\text{label}_2\right\},\ldots \right\}$. This is the form you want.

Once you start specifying Ticks you have to specify all of them. For this case you can use Range and Replace so you don't have to type them all out.

Range[0,15,5] (* {0, 5, 10, 15} *) 

These are the Ticks for the axis. You want $10$ to be Replaced with $\text{L}$ using the Ticks format above.

Range[0, 15, 5] /. {10 -> {10, "L"}} (* {0, 5, {10, "L"}, 15} *) 

Now throw that into Plot

Plot[x, {x, 0, 15}, Ticks -> {Range[0, 15, 5] /. {10 -> {10, "L"}}, Automatic}]

enter image description here

$\endgroup$
1
  • $\begingroup$ -- Thanks. My problem was that I was not specifying each Tick mark. Given the syntax of the specification where the Tick value number was required, I figured that you could specify individual Tick marks. In fact, I think it makes more sense if it worked the way I thought it did so you could specify all, or some, or one of the Tick marks per your pleasure. $\endgroup$ Commented Nov 12, 2015 at 15:58
1
$\begingroup$
Plot[ Sin@x, {x, -Pi, Pi}, Frame -> True, FrameTicks -> {{All, None}, {{-Pi/2, 0, {Pi/2, Row[{Pi/2, " L"}], 0.01}}, None}}] 

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Thanks for the example. But, this is annotating the frame box and I would like to annotate the actual X-axis. Is that possible? $\endgroup$ Commented Nov 11, 2015 at 2:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.