Wolfram Computation Meets Knowledge

Mathematica Q&A: Plotting Trig Functions in Degrees

Got a question about Mathematica? The Wolfram Blog has answers! We’ll regularly answer selected questions from users around the web. You can submit your question directly to the Q&A Team using this form.

This week’s question comes from Brian, who is a part-time math teacher:

How do you plot trigonometric functions in degrees instead of radians?

Trigonometric functions in Mathematica such as Sin[x] and Cos[x] take x to be given in radians:

Trigonometric functions

Plot trigonometric function

To convert from degrees to radians, multiply by π ⁄ 180. This special constant is called Degree in Mathematica.

Cos [180 Degree]

Cos [180 Degree]

The symbol ° is a handy shorthand for Degree and is entered as Esc-d-e-g-Esc. You can also find this symbol in the Basic Math Assistant palette in the Palettes menu of Mathematica.

Using either Degree or °, you can plot trigonometric functions in degrees:

Plot in degrees

Plot in degrees

That answers the main question, but here’s a related hint.

When plotting trigonometric functions in degrees, you might also want to manually specify exactly where Mathematica draws tick marks. You can do this using the Ticks option:

Ticks option

Ticks option

(Here, Range[0, 360, 45] specifies the tick marks on the x axis, and Automatic uses the default tick marks on the y axis.)

The Ticks option is very flexible. You can specify where tick marks are drawn, what labels they should have, how long they are, and even colors and styles.

Download the Computable Document Format (CDF) file for this post to see how to get the custom tick marks used in this plot:

Custom ticks plot

If you have a question you’d like to see answered in this blog, you can submit it to the Q&A Team using this form.

Download the CDF file

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.

8 comments

  1. Wouldn’t it be more logical to write it as Sin[theta] and theta is from 0° to 360°? In that case, the axis would still be labeled in radians, right? ;-) Of course, Ticks fix all that, but the notation of the code is not necessarily the most natural one.

    Reply
  2. If I understand it right, Plot[ SIn[theta], {theta,0,360} ] plots with major ticks at multiples of decades or something – still in degrees, not radians.
    Good post. thanks.

    Reply
  3. This tip helped me a lot, thanks.

    Reply
  4. good article..
    i’ve also try to write it in Pi based in your code…
    ==========================
    majorticks =
    Table[{\[Theta], Row[{\[Theta]}]}, {\[Theta], 0, 2 Pi,
    1/3 Pi}]; minorticks =
    Table[{\[Theta], Spacer[{0, 0}], {0.005, 0}}, {\[Theta], 0, 2 Pi,
    1/8 Pi}];
    Plot[Sin[\[Theta]], {\[Theta], 0, 2 Pi},
    Ticks -> {Join[majorticks, minorticks]}]
    ========================

    Reply
  5. Be careful though: Working in degrees, the derivative of sine is not cosine.

    Reply
  6. This is another possibility. :-)

    Plot[{Sin[theta ], Cos[theta]}, {theta, 0 Degree, 360 Degree},
    Ticks -> {Range[0 Degree, 360 Degree, 45 Degree]}]

    Reply
  7. Dear Sir,
    Thank you kindly for a reply.
    I met an Oxford student last night and he
    wrote quite a script. I found your solution
    is fine.Thanks to the other bloggers too.
    Brian

    Reply
  8. Merci, je n’y avait même pas pensé. exquis !

    Reply