7
$\begingroup$

This is the code I'm using:

 Show[{graph1, graph2},
 PlotRange -> Automatic,
 AxesLabel -> {"\[Lambda](nm)", "k and n"},
 Frame -> {{True, False}, {True, False}}, 
 FrameLabel -> {"Wavelength (nm)", "k,n values"},
 BaseStyle -> {18, FontFamily -> "Helvetica"}, FontColor -> Blue]

enter image description here

My problem is that I can't figure out how to add a plot legend.

$\endgroup$
2
  • $\begingroup$ You can only use options for Graphics with Show, not options for the original functions that created the plots. If you want to use PlotLabel then you should do it in the command you use to create graph1 or graph2. $\endgroup$ – C. E. Jun 25 '17 at 17:54
  • $\begingroup$ Duplicate? (3518), (51880). If you no longer have the original data, but do have the plot Graphics, see (19859) and (59805) $\endgroup$ – Mr.Wizard Jun 25 '17 at 19:31
8
$\begingroup$

For example, writing:

p1 = Plot[x^2, {x, 0, 1}, PlotLegends -> LineLegend[{Blue}, {"y1"}], PlotStyle -> Blue];

p2 = Plot[x^3, {x, 0, 1}, PlotLegends -> LineLegend[{Red}, {"y2"}], PlotStyle -> Red];

Show[{p1, p2}, AxesLabel -> {x, y}]

I get:

enter image description here

which is what you want.

$\endgroup$
5
$\begingroup$

Since you are plotting lists of data points, why not plot the two data sets on one list plot?

{data1, data2} = Table[{t, #[t]}, {t, 0, 2 π, .2}] & /@ {Sin, Cos};
ListPlot[{data1, data2},
  PlotStyle ->
    {Directive[AbsolutePointSize[8], Red], Directive[AbsolutePointSize[8], Blue]},
  BaseStyle -> 18,
  Frame -> {{True, False}, {True, False}}, 
  FrameLabel -> {"Wavelength (nm)", "k,n values"},
  PlotLegends -> {"k values", "n values"},
  ImageSize -> 500]

plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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