0
$\begingroup$

When i want to save the output ,which includes a plotlegends option in it, i can not save the output graph or in other words, the mathematica does not offer the suggestions bar! For example

Plot[Sin[x], {x, 0, 0.2}, PlotLegends->"sin"]

Can anybody help me.

Thanks

$\endgroup$

closed as off-topic by Feyre, corey979, MarcoB, happy fish, gwr Mar 1 '17 at 10:36

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Feyre, happy fish, gwr
  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – corey979, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ i can not save the output graph This is not clear. Try to add more words to describe the problem. Do you want to Export the plot? $\endgroup$ – Nasser Feb 25 '17 at 18:06
  • $\begingroup$ Yes. I want export as, say png. But suggestions bar does not offer options for extract $\endgroup$ – PhysicsExams Feb 25 '17 at 18:37
  • $\begingroup$ To export, just do p=Plot[....] and then just do Export["foo.png",p] You might first want to do SetDirectory[NotebookDirectory[]], so the the file "foo.png" gets saved in same folder as notebook so easy to find. This is what I do for all my HWs. But I suggest you save to PDF and not PNG. PDF is vector graphics. Works for any resolution. $\endgroup$ – Nasser Feb 25 '17 at 18:40
  • $\begingroup$ @PhysicsExams What you mean by suggestion bar? $\endgroup$ – zhk Feb 25 '17 at 18:50
  • 1
    $\begingroup$ @MMM reference.wolfram.com/language/guide/… $\endgroup$ – Mr.Wizard Feb 25 '17 at 21:36
3
$\begingroup$

If you meant to say that the legend line is not showing then you need PlotLegends ->{},

Plot[Sin[x], {x, 0, 0.2}, PlotLegends -> {"sin"}]

enter image description here

Legends inside the plot frame

But if you want to save the image along with the legends then, bring the legend inside the frame, then you will be able to save the plot and legend in the same image,

Plot[Sin[x], {x, 0, 10}, 
 PlotLegends -> Placed[LineLegend[{"sin"}, LegendFunction -> Frame, 
    LegendMarkerSize -> {{55, 10}}], {0.8, 0.2}], Frame -> True]

enter image description here

Rasterize

You can avoid using Export to save image along with the legends by using Rasterize

Rasterize[Plot[Sin[x], {x, 0, 0.2}, PlotLegends -> {"sin"}]]

enter image description here

Export

As suggested by @Nasser, Export will directly save the image with any extension along with legends.

Plot[Sin[x], {x, 0, 0.2}, PlotLegends -> {"sin"}];
Export["C:/tcdata/myimage.png", %]
$\endgroup$
  • 2
    $\begingroup$ But if you want to save the image along with the legends then, bring the legend inside the frame Actually, the Export command will save the plot along with the legend without having to put the legend inside the frame. That is why the question is not clear what the problem is. But +1 for showing how to put the legend inside. This can be useful sometimes $\endgroup$ – Nasser Feb 25 '17 at 18:39
  • $\begingroup$ @Nasser I never tried exporting an image. For my personal plotting, I use Tecplot. But thanks, now I know about it (plot with legend saving). $\endgroup$ – zhk Feb 25 '17 at 18:46

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