# Adding labels and numbers in axes

Let's see the following test case

data = Table[{RandomReal[{-10, 10}], RandomReal[{-10, 10}]}, {i, 1, 50}];
l0 = ListPlot[data, PlotStyle -> {Blue, PointSize[0.01]}];
p0 = Plot[x*Sin[x], {x, -10, 10}, PlotStyle -> {Red, Thick}];
s0=Show[{l0, p0}, Frame -> True, FrameLabel -> {"x", "y"}, Axes -> False,
GridLines -> {{1.5, 7}, {}},
GridLinesStyle -> Directive[Black,Thickness[0.004], Dashed],
Method ->  {"GridLinesInFront" -> True}, PlotRange -> {{0, 10}, {-10,10}},
ImageSize -> 550]


which produces

First a minor point: Even though that I define inside Show the plot range to be {{0,10},{-10,10}}, we see that in the plot both axes exceed the defined limits (i.e., the -0.5 < x < 10.5 instead of [0,10]).

Now my questions:

(a). I would like to add at the position of the vertical lines on the x-axis custom labels like text "P1" and "P2".

OR

(b) Force the program to add the numbers 1.5 and 7 in the horizontal x-axis but without changing the range, I mean to keep the (0,2,4,6,8,10) and add two more inside.

Any suggestions?

• Your minor point can be solved using PlotRangePadding->0 Sep 26, 2014 at 11:52
• Add option FrameTicks -> {{1.5, 7}~Join~Range[0, 10, 2], Automatic} Sep 26, 2014 at 11:57

Show[{l0, p0},
Frame -> True,
FrameLabel -> {"x", "y"},
FrameTicks -> {{Automatic, None},
{{0, {1.5, Style["P1\n1.5", Red, 14]}, 2, 4,
6, {7, Style["P2\n7.0", Red, 14]}, 8, 10}, None}},
Axes -> False,
GridLines -> {{1.5, 7}, {}},
GridLinesStyle -> Directive[Black, Thickness[0.004], Dashed],
Method -> {"GridLinesInFront" -> True},
PlotRange -> {{0, 10}, {-10, 10}},
ImageSize -> 550]


To solve your "minor point" I have added the option PlotRangePadding -> 0.

• Do you know about the SE Uploader palette? I ask because I've noticed your graphics don't look very clean. Sep 26, 2014 at 12:15
• Yes it works however by editing manually the ticks all the minor ticks are not shown any more. Why? Can this be fixed? Sep 26, 2014 at 12:51
• @Vaggelis_Z The same problem appears in the Doxumentation. A certain fix: Replace the last None in my Frameticks-option with Automatic. Now you see the minor ticks at the top of the frame. BTW, thanks for acceptance :)
– eldo
Sep 26, 2014 at 13:05
• @RunnyKine Thank you so much. SE Uploader installation went very well and - after watching the video - I could make it work easily. A very clever app :)
– eldo
Sep 26, 2014 at 17:59

Perhaps,

s0 = Show[{l0, p0}, Frame -> True, FrameLabel -> {"x", "y"},
Axes -> False, GridLines -> {{1.5, 7}, {}},
GridLinesStyle -> Directive[Black, Thickness[0.004], Dashed],
Method -> {"GridLinesInFront" -> True},
PlotRange -> {{0, 10}, {-10, 10}}, ImageSize -> 550,
FrameTicks -> {{0, {1.5, Style[1.5 , Red, Bold]}, 2, 4,
6, {7, Style[7, Red, Bold]}, 8}, Automatic},
Epilog -> {Text[Framed["P1"], {1.5, 0}, {-1, 1}],
Text[Framed["P2"], {7, 0}, {-1, 1}]}]


• I have the same comment as in eldo's answer. All the minor ticks of the x-axis are no longer visible. Why? Sep 26, 2014 at 12:52