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?

  • 2
    $\begingroup$ Why not put the two ListPlot[]s together? plt2 = ListPlot[{{{1, 1}, {0.5, 0.5}}, {{0.4, 1}, {0.2, 0.5}}}];? $\endgroup$ – J. M. is in limbo Jul 22 '15 at 5:10
  • $\begingroup$ You could also specify PlotStyle colors manually if needed for some reason. If you wish to match the defaults see (54629) $\endgroup$ – Mr.Wizard Jul 22 '15 at 6:09
  • $\begingroup$ 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). $\endgroup$ – leosenko Jul 22 '15 at 6:18
  • $\begingroup$ 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. $\endgroup$ – J. M. is in limbo Jul 22 '15 at 7:00

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


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