Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there a simple way, besides changing my function to use Degree as input, to display the x-axis in degrees in a plot of a function defined with its independent variable taking radians?

share|improve this question
1  
It does not get simpler than Plot[f[x Degree],{x,-1,1}] , and you can control exactly what is shown on the axis with the Ticks option of Plot. Theoretically you could do post-processing on the Graphic object but that seems to me to be overkill. –  William Briand Mar 13 at 20:00
    
not about Degree but duplicate imo. Also related –  Kuba Mar 13 at 20:46

2 Answers 2

f[range_List, divs_] := {# Pi/180, # Degree} & /@ FindDivisions[range 180/Pi, divs, 10]; 
plot[g_, range_]:= Plot[g[x], Evaluate@Join[{x}, range], Ticks-> {f[range, 10], Automatic}];
g = Sin;
plot[g, {0, 2 Pi}]

Mathematica graphics

share|improve this answer
    
Interesting, I din't know about FindDivisions. +1 –  Murta Mar 13 at 20:25
    
@Murta The function doesn't work very well. The standard Plot[] automatic ticks are much more robust. –  belisarius Mar 14 at 0:27

Here is a slightly different way to do it. It has the advantage of accepting the options of Plot.

SetAttributes[degreePlot, HoldAll]
degreePlot[f_, range_, opts : OptionsPattern[Plot]] :=
  Plot[f[x Degree], {x, range[[1]], range[[2]]}, 
    Evaluate @ FilterRules[Join[{opts}, {Ticks -> range}], Options[Plot]]]
degreePlot[Sin, {0, 360, 10}, Frame -> True, PlotStyle -> Red]

plot

share|improve this answer
    
Thanks Would you also tell me what does @ and @@ mean in mathematica, I see it all the time but cannot figure out what it means even after some googling..Thanks –  henry leung Mar 14 at 5:37
    
@henryleung. @ is the prefix form of for a function call; f @ x is essentially the same as f[x]. Similarly, f @@ h[x] is essentially the same as Apply[f, h[x]]. You can find more at Prefix and Apply –  m_goldberg Mar 14 at 10:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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