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.

I can use PolarPlot to generate a plot; however, I would like to rotate the plot by 90 degrees and then output the result using Show. Here is the code

Y20 = 
  PolarPlot[
     Abs[Sqrt[5/(16*Pi)]*(3*Cos[Theta]^2 - 1)], 
     {Theta, 0, 2*Pi}, 
     Ticks -> None
  ]
Show[Rotate[Y20, Pi/2]]

enter image description here

and the error

Show::gtype: Rotate is not a type of graphics.

If I wrap Rotate with Graphics the error message I get is

Graphics is not a Graphics primitive or directive.

Any comments will be welcomed.

share|improve this question
1  
What about Rotate[Y20, Pi/2]? –  Kuba Mar 25 at 21:47
    
Why would Show be needed? –  Sjoerd C. de Vries Mar 25 at 22:10
    
Maybe to combine with another Graphic? –  Andy Mobley Mar 25 at 22:12
2  
@AndyMobley Good point. So: Graphics[Rotate[Y20[[1]], Pi/2, {0, 0}]] may be used in Show. –  Kuba Mar 25 at 22:25
    
@Kuba: The method in your original comment certainly works. Why not make it an answer? –  murray Mar 25 at 22:28

1 Answer 1

Rotate is a quite strightforward function; it does what you want.

You use Rotate on something that is not a Graphics primitive? No problem, it will give what you ask:

Rotate[longvariablename, Pi/2]

enter image description here

That is the problem in your approach:

  • Y20 is not a graphics primitive so it will be treated as above. So you see you can't pass it to Show. It's no longer just Graphics (RotationBox is created - more at the end...).

So what to do? We have to take from Y20 the primitives, Rotate them and put back into Graphics.

You can read for example How to examine structure of graphics to learn more but usually it is simple; for example, Plots and friends (with exclusion of Graphs) are producing:

 Graphics[{primitives..}, options..] (*or, for more complicated like ContourPlot*)

 Graphics[GraphicsComplex[], options..] (*Normal[] can convert it back to simple form*)

for both cases first argument is what you need. Everything is an expression so it is again straightforward:

Graphics@Rotate[Y[[1]], Pi/2, {0,0}] 
(*so exactly what I've said we need to do, take-rotate-put back*)

Show takes Graphics so you can combine it with whatever you want:

Show[{
      Plot[Sin[x], {x, -1, 1}, PlotStyle -> Red],
      Graphics[Rotate[Y20[[1]], Pi/2, {0, 0}]]},
     PlotRange -> 1, AspectRatio -> Automatic, BaseStyle -> {18, Bold, Thick}]

enter image description here

Keep in mind that Show, as said in documentation, takes its Options from the first argument, here Plot. It doesn't matter for this context, just pointing it out. More here


An observation about RotationBox. I'd be very thankful for credible support here :)

RotationBox is created whenever you use Rotate outside Graphics. But when you use it on Graphics primitives it will convert to GeometricTransformationBox inside Graphics. If not you will get an error that you have provided non primitive object for Graphics.

share|improve this answer
    
I didn't want to say more about creating graphics because I'm not informed enough. Not very important for the context too but if anyone want, it would be nice addition. –  Kuba Mar 25 at 23:34

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.