1
$\begingroup$

I plotted a simple function with:

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

enter image description here

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)

$\endgroup$
4
$\begingroup$
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]

enter image description here

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]

enter image description here

$\endgroup$
  • $\begingroup$ 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`}]} $\endgroup$ – Unbelievable Nov 22 '15 at 19:44
1
$\begingroup$

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]

enter image description here

$\endgroup$
  • $\begingroup$ Besides so much thanks for your guidance but because I am not professional, using eldo's answer was easier for me. $\endgroup$ – Unbelievable Nov 22 '15 at 19:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.