2
$\begingroup$

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?

$\endgroup$

closed as off-topic by Mr.Wizard Jul 22 '15 at 6:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 away 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 away Jul 22 '15 at 7:00
3
$\begingroup$

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

$\endgroup$

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