# FrameTicks and Ticks on Axes in Same Plot

I have a plot where I would like ticks shown on both the axes and the frame, with them labeled separately. I have custom labels for the frame and want the horizontal axis labeled with ticks automatically. Despite setting both the Ticks and the Frame properties, I cannot get the ticks to show up on the axes. Is there a way to do this without drawing the ticks manually or something like that? My example is shown below, I am able to get automatic ticks on the top of the frame, but these are not labeled either.

Plot[xt[t], {t, 0, .5*10^-3},
Ticks -> Automatic,
FrameLabel -> {{"x [m]", None}, {"t", None}},
Frame -> True,
FrameTicks -> {{Automatic, None}, {{{0, "t'"}, {.0005, "t'+5 ms"}}, Automatic}}]


• Since you said Frome->True then you need to use just FrameTicks not Ticks. Mar 24, 2014 at 0:25
• Right, I have FrameTicks, as shown in the example, but I also want (different) ticks on the axes line in the middle of the graph. Mar 24, 2014 at 0:30
• I understand that what you wanted, but when Frame->True then Ticks is ignored and not even looked at. So there is no point of even having it there. That is what I mean. Try Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, Ticks -> {{1, 1}}] so the actual ticks will have to come from FrameTicks which you already specified. Mar 24, 2014 at 0:39
• @DamianManda Thanks for the accept. Notice that you can also upvot all the answers you find useful. (with that gray triangle next to each answer)
– Kuba
Mar 25, 2014 at 5:50

As noticed in this topic it is impossible an could be confusing. The solution is as usual, Overlay :)

With[{opt = Sequence[ImagePadding -> {{65, 25}, {40, 15}}, BaseStyle -> {Bold, 15}]},

Overlay@{

Plot[Sin[t], {t, 0, 2 Pi}, FrameLabel -> {{"x [m]", ""}, {"t", ""}}, Frame -> True,
FrameTicks -> {{Automatic, None}, {{{0, "t'"}, {2 Pi, "t'+5 ms"}}, Automatic}},
Axes -> False, opt],

Plot[Sin[t], {t, 0, 2 Pi}, Axes -> {True, False}, PlotStyle -> None, opt]
}]


• Thanks, this is what I was looking for. I realize it can be confusing in some circumstances but wanted it for this case. In case anyone else also wants to then resize the plot (it doesn't have handles), you can add ImageSize->Large to the opt sequence. Mar 25, 2014 at 5:51
• @DamianManda Agree. Just set the size as you want. You can use Rasterize at the end to conver it to bitmap.
– Kuba
Mar 25, 2014 at 6:07

Here is a solution that doesn't use Overlay, making the result still a Graphics object.

Using the function extraAxisPlot, defined in this post, you get

extraAxisPlot[
Plot[Sin[10^5 t] (.7 10^-3 - t), {t, 0, .5*10^-3},
Ticks -> Automatic,
FrameLabel -> {{"x [m]", None}, {"t", None}},
Frame -> True,
ImageSize -> 450,
FrameTicks -> {{Automatic, None}, {{{0, "t'"}, {.0005, "t'+5 ms"}},
Automatic}}],
{0, .5*10^-3},
{0, 0}
]


The arguments to extraAxisPlot are the original plot, the range of the extra axis, and the initial point for it to start at.

AxisObject was introduced in version 12.3 to solve just this type of problem:

Plot[Sin @ t,
{t, 0, 2 * Pi},
FrameLabel -> {{"x [m]", ""}, {"t", ""}},
Frame -> True,
FrameTicks -> {
{Automatic, None},
{{{0, "t'"}, {2 * Pi, "t'+5 ms"}}, Automatic}
},
Axes -> False,
Prolog -> AxisObject[{"Horizontal", 0}]
]


Since AxisObject is a graphics primitive, I'm just feeding it in using the Prolog option to Plot.

Since you do not provide a definition for x[t], I can't reproduce your plot, but maybe the following code will suggest a work-around that you will find satisfactory.

Plot[Sin[t], {t, 0, 2. Pi},
Frame -> True,
FrameLabel -> {{"x [m]", None}, {"t", None}},
FrameTicks -> {{Automatic, None}, {{{0, "0"}, {Pi, "π"}, {2 Pi, "2\[ThinSpace]π"}}, All}}]


As you can see, changing the specification of the top ticks from Automatic to All makes the default labeling visible.

• I assumed they wanted on the lower x-axis the same ticks as the top axis (i.e more ticks), but in addition to add those 2 edges special tick labels they had. (you are right, it would have been better to have xt[t] there also). may be OP can clarify. Mar 24, 2014 at 1:24