Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating some plots with Show but unfortunately the PlotLegends seems to be out of the bounding box when saving the graph.

Sample code:

data1 = {1, 2, 3};
data2 = {3, 4, 5};
Show[ListPlot[data1, PlotLegends -> {"Somedata1"}], 
ListPlot[data2, PlotLegends -> {"Somedata2"}]]

Is there a way to include them so they can be exported along with the image?

share|improve this question
@YvesKlett, ill fix that straight away. – JavaCake May 24 '13 at 7:28
@YvesKlett, went a tad too quick. It should be fixed now. – JavaCake May 24 '13 at 7:36
If you want to export it as a raster image, you can always use Rasterize. – nikie May 24 '13 at 9:10
Have you tried the legendMaker and the autoLegend functions in this post? It works perfectly for me and is the best solution for legends in MMA I've ever discovered on this site. – Leo Fang Jun 19 '13 at 1:08
Actually, you can use Export command to export your result as a picture such that Export["test.jpg",(*your result*)]. By this way the legend is included. – Z-Y.L Feb 17 '14 at 5:57
up vote 12 down vote accepted
data1 = RandomReal[10, {10}];
data2 = RandomReal[10, {10}];
Show[ListPlot[data1, PlotLegends -> Placed[{"Somedata1"}, {1, .5}]], 
ListPlot[data2, PlotLegends -> Placed[{"Somedata2"}, {1, .4}]]]

For different colors, just one ListPlot is enough sometimes.


enter image description here

share|improve this answer

I have found a way of making a pdf or eps file from a Plot with a Legend. Click on the plot till everything is selected, including the legends. Then save it a a pdf or eps file.... and that is it.

share|improve this answer

Instead of Show[], you should use all the data set in a single Plot[] (for your case it is ListPlot[]). It will automatically assign different Style or PlotMarker to distinguish different plots. And you can always put the legend at your desired position. As an example

data1 = Table[{x, Sin[x]}, {x, 0, 2 Pi, .1}]; label1 = "Sine";
data2 = Table[{x, Cos[x]}, {x, 0, 2 Pi, .1}]; label2 = "Cosine";

position = {0.25, 0.25};
size = {0.3, 0.2};
ListPlot[{data1, data2}, PlotStyle -> {Black, Red}, PlotLegend -> {label1, label2}, LegendShadow -> None, LegendBorder -> Automatic, LegendSize -> size, LegendPosition -> position]

You can easily vary the position of your Legend and in will be in the same place in exported file as well.

share|improve this answer

Your Answer


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.