6

I have Plot and ListPlot and I want to combine the using Show:

plt = Plot[{Cos[x], Sin[x]}, {x, 0, 2}];
plt2 = ListPlot[{{1, 1}, {0.5, 0.5}}];
plt3 = ListPlot[{{0.4, 1}, {0.2, 0.5}}];
Show[plt, plt2, plt3]

But the problem is with colouring the ListPlots. Let's say I would like plt2 markers have the same colour as Cos[x] and plt3 the same colour as Sin[x]. How would I do it?

atapaka
  • 3,954
  • 13
  • 33
  • 2
    Why not put the two ListPlot[]s together? plt2 = ListPlot[{{{1, 1}, {0.5, 0.5}}, {{0.4, 1}, {0.2, 0.5}}}];? – J. M.'s missing motivation Jul 22 '15 at 05:10
  • You could also specify PlotStyle colors manually if needed for some reason. If you wish to match the defaults see (54629) – Mr.Wizard Jul 22 '15 at 06:09
  • I am sorry, I wanted an automated solution. I know how to do it manually, but such a solution is rather clumsy and yes, that is trivial. But what I want is a nice automated solution (like use the same colour for listplot as you used for plot). – atapaka Jul 22 '15 at 06:18
  • In that case, you need to explicitly set PlotStyle. Mr. Wizard has already linked you to the thread on how the default colors are generated. – J. M.'s missing motivation Jul 22 '15 at 07:00

1 Answers1

9

PlotStyle is your Friend.

plt = Plot[{Cos[x], Sin[x]}, {x, 0, 2}
   , PlotStyle -> {{Red, Thick}, {Blue, Thick}}];
plt2 = ListPlot[{{1, 1}, {0.5, 0.5}}, PlotStyle -> Red];
plt3 = ListPlot[{{0.4, 1}, {0.2, 0.5}}, PlotStyle -> Blue];
Show[plt, plt2, plt3]

enter image description here