idl-programming-language

Plotting in degrees instead of radians


I have plotted a graph that contains a trig function. Instead of having the x-axis be in radians, I would like it to be in degrees. It's a simple task of multiplying the displayed x-axis values by 180/!pi but I can't figure out how to do it. Let's say I'm trying to graph the cosine function as

q=plot(cos(x))

How can I change the displayed x-axis values to degrees?


Solution

  • Just pass the x-values to the plotting routine:

    x = findgen(360)
    y = cos(x * !dtor)
    plot, x, y
    

    Or, if you are using function graphics:

    p = plot(x, y)