2

How can I show Pi instead of numbers in x-axis of the plot below?

Plot[{Sin[t], Cos[t]^2, Cos[t]}, {t, -Pi/2, Pi/2}, PlotStyle -> {Red, Blue, Orange}]
kglr
  • 394,356
  • 18
  • 477
  • 896
Holger Mate
  • 183
  • 5

1 Answers1

6

You can create a custom Ticks function using FindDivisions:

  • FindDivisions[{$x_{min}$,$x_{max}$, {$dx_1$, $dx_2$, …}},{$n_1$, $n_2$, …}]
    uses spacings that are forced to be multiples of $dx_1$, $dx_2$, ….

 ticksF = Join[Thread[{#, #, {0.03, 0.}, Thickness[0.005]}, List, 2], 
     Thread[{Complement[Join @@ #2, #], "", {0.02, 0.}, Thickness[0.003]}, List, 1]] & @@ 
    FindDivisions[##] &;

Plot[{Sin[t], Cos[t]^2, Cos[t]}, {t, - Pi / 2, Pi / 2}, 
  PlotStyle -> {Red, Blue, Orange}, 
  Ticks -> {ticksF[{-Pi / 2, Pi / 2,  {Pi/8, Pi / 32}}, {4, 10}], Automatic}, 
  AxesStyle -> Thick]

enter image description here

Use

Ticks -> {ticksF[{-Pi/2, Pi/2, {Pi/8, Pi/32}}, {8, 10}], Automatic}

to get

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896