13
$\begingroup$

Sorry I am not sure if I got anything wrong with this version of Mathematica and Mac OS X i am running. But every time I export a 3D graph, to png or tiff, I lost the view angle, view vector viewpoint information immediately. To let you know what I meant, here is a simple code:

I typed:

x = RevolutionPlot3D[Sqrt[((t/5)^2 - 1)*2], {t, 5, 20}]

And I got a plot

out[1]= 

Original Plot

Then I manually rotate the plot so that it looks better, for example like this: Manually rotated view

Ok, now, I used Export to export it to png:

Export["test.png", %];

What I got is pathetically, the un-rotated png plot!: Exported png

This is driving me crazy and dead.. I also tried to set Viewpoint and view vector, stuff to the code, it doesn't work for me either. I also tried Export["test.png",x] too, no luck. I understand I could easily right-click to save, But I need a background-none option to make the graph transparent..

Can any one confirm (this bug?) or i am doing something stupidly wrong? I checked the documentation and googled for 1 hour, nothing found.

So the question is, how can I export the graph as it is shown on the notebook (if I can not, then what's the point of allowing us to rotate it..)

$\endgroup$
8
  • 1
    $\begingroup$ RightClick + Save Graphics As... or File/Save Selection As... or Export["test.png", actual graphics] $\endgroup$
    – Kuba
    Commented Apr 9, 2014 at 9:10
  • 1
    $\begingroup$ You need to Export the actual rotated graphics or set the view options specifically. x is not changed by you rotating its graphical avatar. Related: mathematica.stackexchange.com/q/5375/131 $\endgroup$
    – Yves Klett
    Commented Apr 9, 2014 at 9:24
  • 3
    $\begingroup$ What did you mean by this? - "PS. I will be grateful like a dead man if Mathematica support plot tools like Matlab." $\endgroup$ Commented Apr 9, 2014 at 9:33
  • 2
    $\begingroup$ @VitaliyKaurov yes, this sentence is somewhat open to interpretation :D $\endgroup$
    – Yves Klett
    Commented Apr 9, 2014 at 9:45
  • 3
    $\begingroup$ You have two good answers so I'll just comment to emphasise that % does not refer to the contents of the last output cell, it refers to the last output expression from the kernel. Nothing you do to the output cell changes the expression stored in %, whether it's rotating the graphics or even deleting it entirely and replacing it with a photo of your cat. $\endgroup$ Commented Apr 9, 2014 at 12:22

4 Answers 4

23
$\begingroup$

What is stored in variable x is different from rotated object you have in output cell. You rotated - so you changed the properties. Many ways to do this - so in addition to comments' methods...

1) In-Export rotation

enter image description here

2) Seeing options

enter image description here

Export["test.png", Show[x, opts]]
$\endgroup$
4
  • $\begingroup$ OP may be confused because he is not using x but %. $\endgroup$
    – Kuba
    Commented Apr 9, 2014 at 9:35
  • $\begingroup$ @Kuba yes, good point, I hope he reads comments ;-) $\endgroup$ Commented Apr 9, 2014 at 9:36
  • $\begingroup$ Hi @Kuba thanks so much. I actually tried to export x directly, the result is the same (un-rotated png)~ I will try to copy the output to export to see thanks! $\endgroup$
    – bboczeng
    Commented Apr 9, 2014 at 17:51
  • $\begingroup$ In Export-Rotation works for me! $\endgroup$
    – bboczeng
    Commented Apr 9, 2014 at 18:05
7
$\begingroup$

To save a PNG of a plot or graphics expression, I avoid Export. I select the displayed output and click on the Save Selection As ... item on the File menu. This will save the selected output exactly as it appears on the display.

saving-plot

$\endgroup$
2
  • $\begingroup$ Hi @m_goldberg . The reason I wanted to use export is to make the background transparent. ! Save as can not make the background transparent. Thanks for your answer! $\endgroup$
    – bboczeng
    Commented Apr 9, 2014 at 17:52
  • $\begingroup$ also export can make the figure much better by setting ImageResolution->500 or so. $\endgroup$
    – bboczeng
    Commented Apr 9, 2014 at 18:12
0
$\begingroup$

Mathematica has Export for 3D I'm unsure how well it exports to 3DStudio (in past versions, poorly).

The (see URLs) can Export to Renderer format (rayshade or povray) and does preserve things (the whole scene hopfully including text and tick marks - though that is little tested it has examples of 2D plots doing it well) - when they are supported (many things are, many not, Mathematica 11.0 is simply too huge to comment on).

see How to Render, raytrace, Export Graphics3D in Mathematica 11.0

and

https://sourceforge.net/projects/rayshade-math/

Both rayshade and povray can be used to Rotate (manipulate) the resulting output realtime without Mathematica.

$\endgroup$
0
$\begingroup$

I like following solution which needs no context menu. The mouse is only needed to adjust the ViewPoint. It uses the answer by Yves Klett to Extract current viewing parameters from a 3D view?.

vp = Options[Graphics3D, ViewPoint][[1, 2]];
elongatedSquareGyrobicupola = 
   Graphics3D[{Gray, EdgeForm[{Thick}], 
     PolyhedronData["ElongatedSquareGyrobicupola", "GraphicsComplex"]}, 
    ViewPoint -> Dynamic[vp], Lighting -> "Neutral", Boxed -> False]

Now do your manual adjustment of the ViewPoint and then add the export routine

enter image description here

Export["out.pdf", 
 GraphicsRow[{Show[
    elongatedSquareGyrobicupola, {ViewPoint -> Dynamic[vp]}]}, 
  ImageSize -> 1000]](*export as vector graphics*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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