7

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • 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. – C. E. Jun 25 '17 at 17:54
  • Duplicate? (3518), (51880). If you no longer have the original data, but do have the plot Graphics, see (19859) and (59805) – Mr.Wizard Jun 25 '17 at 19:31

2 Answers2

8

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.

πρόσεχε
  • 4,452
  • 1
  • 12
  • 28
5

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257