Message Boards Message Boards

How to export a plot (or graph) together with its legend?

Posted 9 years ago
POSTED BY: Rene Samson
5 Replies
Posted 9 years ago

Tnx David....So nice!

POSTED BY: Hadi Tokme
Posted 9 years ago

I also find that with Version 10.3 on Windows you can select the cell containing the graphic, right-click, and choose "Save Selection As" to save a graphic which will include the legend:

enter image description here

The saved png is:

enter image description here

POSTED BY: David Keith
Posted 9 years ago

David's suggestion was the easiest and fastest solution for me. Thanks a heap. René Samson

POSTED BY: Rene Samson
Posted 9 years ago

I find that when using legends created by PlotLegends, selecting the graphic and then using "Save graphic as" does not include the legend, apparently because the legend graphic is not selectable. However, assigning the graphic to a variable and using export does include the legend. For example:

p1 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, 
   PlotLegends -> "Expressions"];

Export["exportP1.png", p1]

will save p1 as a png and it will include the legend.

I'm on 10.0.2 and Win 7 x64.

POSTED BY: David Keith

Are you used Legended or something similar? Some of the legend functions put the legend inside the same graphics as the plot and some don't. Mathematica graphics are a kind of vector graphics. A simple workaround for many unintuitive graphics problems like this is to rasterize them into an image.

Try wrapping Rasterize[....] around the result or around the commmand producing the plot.

If they're separate graphics and you'd like to not rasterize them, try putting them into a list and combining them with GraphicsRow.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract