2
$\begingroup$

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}]
$\endgroup$
3
  • 1
    $\begingroup$ use the option Ticks -> {Range[-Pi/2, Pi/2, Pi/8], Automatic}? $\endgroup$
    – kglr
    Aug 18, 2018 at 9:52
  • $\begingroup$ Thank you for your comment. Ticks do what I need but I need axis to be more thick @kglr $\endgroup$ Aug 18, 2018 at 9:56
  • 1
    $\begingroup$ This is already a different question. What you need is AxesStyle -> Thick. Have a look at other options and examples of Plot. $\endgroup$
    – Johu
    Aug 18, 2018 at 10:16

1 Answer 1

6
$\begingroup$

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

$\endgroup$

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