A 2D-plot with second X-axis [duplicate]

This question already has an answer here:

FrameTicks and Ticks on Axes in Same Plot

3 answers

I plotted a simple function with:

npi2 = {\[Pi]/2, 3 \[Pi]/2};
npi3 = {\[Pi]/3, 2 \[Pi]/3, 4 \[Pi]/3, 5 \[Pi]/3};
npi4 = {\[Pi]/4, 3 \[Pi]/4, 5 \[Pi]/4, 7 \[Pi]/4};
Plot[Sin[x]^2 Cos[x], {x, 0, 2 \[Pi]}, Frame -> True,
FrameTicks -> {{Automatic, npi3}, {npi4, npi2}}]

But the desired case is to show the roots (which should be automatically calculated) of the function with a special Ticks which be on the x-axis (not as FrameTicks) (exactly on an horizontal axis passed through the origin)

=================

=================

2 Answers
2

=================

fun = Sin[x]^2 Cos[x];

npi4 = {Pi/4, 3 Pi/4, 5 Pi/4, 7 Pi/4};

zeros = Last /@ List @@ Reduce[fun == 0 && 0 < x < 2 Pi, x] plot = Plot[fun, {x, 0, 2 \[Pi]}, Axes -> False,
Frame -> True,
FrameTicks -> {{Automatic, None}, {npi4, None}}];

tics = Line[{{#, 0.02}, {#, -0.02}} & /@ zeros];

text = Text[#, {#, -0.08}] & /@ zeros;

axis = Graphics[{Line[{{0, 0}, {2 Pi, 0}}], tics, text}];

Show[plot, axis]

  

 

It is wonderful and enjoyable. Although for clearness of text on the axis I had to run once text and after that. I rewrite that -0.2 and +0.2 added to the place: text = {Text[[Pi]/2, {[Pi]/2 – 0.2, -0.1}], Text[\[Pi], {\[Pi], -0.1}], Text[(3 [Pi])/2, {(3 [Pi])/2 + 0.2, -0.1`}]}
– Irreversible
Nov 22 ’15 at 19:44

Just for fun. Note in the following the -0.0001 was used to deal with numerical issues to get zero at π\pi:

p = Plot[Sin[x]^2 Cos[x], {x, 0, 2 \[Pi]}, MeshFunctions -> (#2 &),
Mesh -> {{-0.00001}}, MeshStyle -> {PointSize[0.02]}, Frame -> True,
FrameTicks -> {{Automatic, None}, {Range[Pi/4, 7 Pi/4, Pi/2],
None}}]
fun[g_, lst_, eps_] := Module[{pts = g[[1, 1]]},
g /. Point[
x__] :> ({Line[{pts[[#]], pts[[#]] + {0, -eps}}],
Text[First@Nearest[lst, pts[[#, 1]]],
pts[[#]] + {0, -0.025}, {0, 1}]} & /@ x)]
fun[p, {Pi/2, Pi, 3 Pi/2}, 0.03]

  

 

Besides so much thanks for your guidance but because I am not professional, using eldo’s answer was easier for me.
– Irreversible
Nov 22 ’15 at 19:47