If I have the following:

p1 = ListPlot[data];
p2 = Graphics@Line[{{65, 0.056}, {80, 0.056}}];

How can I plot both p1 and p2 together specifying the color for each of them. For instance, I want p1 to be green and p2 to be red. I am using the following

Show[{p1, p2}, PlotStyle -> {Green, Red}] 

but this does not work for those colors.

EDIT: How can I add legends for each of them? say "legend1" for the p1 and "legend2" for the p2


  • 1
    $\begingroup$ ListPlot[data, PlotStyle -> Green] and Graphics[{Red, Line[...]}] should do it. You can't use Show to do styling, it's just for putting graphics together. Note that ListPlot also has Epilog and Prolog options that you can use to draw the line. $\endgroup$
    – C. E.
    May 27 '20 at 17:54
  • $\begingroup$ @C.E. Thanks! I am using p1=ListPlot[data, PlotStyle -> Green] p2 = Graphics[{Red, Line[{65, 0.056}, {80, 0.056}]}] but It still does not work. Is there any sintax error in p2?. Finally I use Show[p1, p2] $\endgroup$
    – John
    May 27 '20 at 18:02
  • 1
    $\begingroup$ Yes, it should be Line[{{65, 0.056}, {80, 0.056}}] $\endgroup$
    – C. E.
    May 27 '20 at 18:04
  • $\begingroup$ @C.E. Thank you! That works ! $\endgroup$
    – John
    May 27 '20 at 18:08
  • 2
    $\begingroup$ @C.E.: To be fair, some options that users might mentally lump in with "styling" (PlotRange, Axes, PlotLabel, Ticks, etc.) can be passed to Show as options. So I wouldn't say that it's strictly true that Show is "just for putting graphics together". $\endgroup$ May 27 '20 at 18:41
data = Transpose[{Range[60, 80], Sin[N@Range[60, 80]]}];

 {data, {{65, 0.056}, {80, 0.056}}},
 PlotStyle -> {Green, Red},
 PlotLegends -> {"legend1", "legend2"}
  • $\begingroup$ Thanks!!! This works ! $\endgroup$
    – John
    May 27 '20 at 18:33
  • $\begingroup$ Good! Always glad to help. =) $\endgroup$ May 27 '20 at 18:34

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.