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 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 at 5:57
add comment

3 Answers

up vote 8 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.

ListPlot[{data1,data2},PlotLegends->Placed[{"Somedata1","Somedata2"},{1,.5}]]

enter image description here

share|improve this answer
add comment

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
add comment

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";

Needs["PlotLegends`"]
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
add comment

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.