Message Boards Message Boards

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

Posted 10 years ago

Dear Mathematica folks,

Who can help me with the following trivial but irritating little problem?

If I make plots in Mathematica, it's straightforward to save and export the plot to another document. However ... if there's a legend attached to the plot, the straightforward "saving" operation in the Mathematica notebook selects only the plot and not the legend. There must be a simple way of locking the legend to the plot so that the "export" operation works on both jointly, but I haven't been to figure out how to do that.

Who can help me?

Thanks in advance, René Samson

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 10 years ago

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

POSTED BY: Rene Samson
Posted 10 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
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