I am plotting two sets of data, when I put legend in each separate graph, then use show, it give me the combined graph with the legend on the right of the graph. After that, when I export the graph in any format it does not show the legend. Could any one help me on how to show the legend in the upper right corner of the graph generated from the show command, and to make it appear in the exported graphic. Best regardsenter image description here

  • 1
    $\begingroup$ Welcome to Mma.SE. Thanks for taking the tour. Be sure you have learned about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. Without code you leave us guessing the details that may be crucial to understand the problem. Please edit your question to improve it. By doing all this you help us to help you and likely you will inspire great answers. $\endgroup$
    – rhermans
    Jul 29, 2018 at 11:49
  • $\begingroup$ @rhermans. Thank you for taking the time to read my question. I think I give all the needed input to my question, the code and the generated graph is in the attached picture. please let me know if more is needed, so I can provide gladly. Best regards $\endgroup$
    – user59148
    Jul 29, 2018 at 12:02
  • 3
    $\begingroup$ Here it's considered helpful to show your own efforts and share code in a well formatted form instead of images or links to external files, so we can quickly Copy&Paste your code, test it, and see the problem you are facing. Crucially, you are not sharing the code you use to export the plot, but even code to create simple plots is welcome, as it save us from typing examples and because sometimes problems come from small typo. Please help us to help you and edit your question accordingly. This question in Meta could be useful. $\endgroup$
    – rhermans
    Jul 29, 2018 at 12:08
  • 2
    $\begingroup$ Please edit your question to clarify whether "show the legend in the upper right corner of the graph" means inside or outside of the Frame. $\endgroup$
    – Bob Hanlon
    Jul 29, 2018 at 14:24
  • $\begingroup$ Based on your problem with exporting the graphics, you may be looking for How can I save both the plot and the legend together? $\endgroup$
    – C. E.
    Jul 30, 2018 at 2:10

1 Answer 1

pos = Placed[#, Scaled@{0.9, 0.75}] &; 
a = ListPlot[Table[Sin[x], {x, 0, 2 \[Pi], \[Pi]/18}], Frame -> True, 
   PlotMarkers -> {Style["+", Blue], 14}, PlotLegends -> pos@{"a"}];
b = ListPlot[Table[Sin[x], {x, 0, 2 \[Pi], \[Pi]/18}], Frame -> True, 
   PlotMarkers -> {Style["O", Red], 10}, PlotLegends -> pos@{"a"}];
Show[a, b]

enter image description here

The {0.9,0.75} in Placed are coordinates of the legend in relative units


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.