2
$\begingroup$

I am trying to superimpose a scatter (Listplot) on a contour plot.

If p1 is a contour plot and p2 is a scatter plot imported from some data, how do I plot them on top of each other?

I tried Show and Overlay but neither worked. Simply gave the error:

Show::gcomb: "Could not combine the graphics objects in Show[p1,p2,PlotRange->All]."

Please help. Thank you! :)

EDIT:

p1 = ContourPlot[
  Min[0.10376 (x^2.5 + Sqrt[2] y^2.5), 
   0.0964395 (x/100000000000000000000000000 + 8 y^2)], {x, 0, 
   0.75}, {y, 0, 0.75}, BaseStyle -> {FontSize -> 20}, 
  Contours -> Function[{min, max}, Range[min, max, 0.002]], 
  ColorFunction -> "BlueGreenYellow", PlotLegends -> Automatic]

p2 = ListPlot[{altdata, sliddata}, PlotMarkers -> Automatic]

where

altdata = {{0.01, 0.01}, {0.05, 0.02}, {0.05, 0.03}, {0.05, 0.04}, {0.05, 0.05}, {0.11, 0.05}, {0.05, 0.06}, {0.11, 0.06}, {0.05, 0.07}, {0.11, 0.11}, {0.18, 0.2}, {0.2, 0.2}, {0.22, 0.2}, {0.24, 0.2}, {0.26, 0.2}, {0.28, 0.2}, {0.3, 0.2}, {0.32, 0.2}, {0.34, 0.2}, {0.1, 0.2}, {0.12, 0.2}, {0.14, 0.2}, {0.16, 0.2}, {0.3, 0.25}, {0.3, 0.3}, {0.3, 0.35}, {0.3, 0.4}, {0.3, 0.45}, {0.3, 0.5}, {0.3, 0.55}, {0.3, 0.6}}

and

sliddata = {{0.05, 0.01}, {0.11, 0.02}, {0.11, 0.03}, {0.11, 0.04}, {0.3, 0.1}, {0.3, 0.15}}

Show[p1, p2]
$\endgroup$
  • 1
    $\begingroup$ Without showing us what p1 and p2 are, we can't help you. $\endgroup$ – J. M. is in limbo May 31 '16 at 17:41
  • 2
    $\begingroup$ Show[ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}], ListPlot[Range[12], PlotStyle -> Red]] $\endgroup$ – BlacKow May 31 '16 at 17:45
  • 1
    $\begingroup$ I cannot reproduce your error using the code you provided. The Show expression works fine here. $\endgroup$ – MarcoB May 31 '16 at 19:36
4
$\begingroup$

Are you looking for

cp1 = ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 4 Pi}, {y, 0, 4 Pi}]
testData = Prime[Range[25]]
lp1 = ListPlot[testData, PlotStyle -> Red]

Show[cp1, lp1]

enter image description here

but be carefull and check the sequence of Show, because Show uses the options from the first graphic

Show[lp1, cp1]

enter image description here

cp2 = ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 25}, {y, 0, 100}]
Show[cp2, lp1]

enter image description here

So, Show[cp2, lp1, PlotRange -> All] is a wrong call for Show, it works without PlotRange -> All, because Show uses the options from the first graphic.

With your Edit and your Data I get:

enter image description here

Is that OK with you?

$\endgroup$
  • $\begingroup$ That is what I tried (and hoped for) but couldn't produce what you just did! Will attempt at it tomorrow (and, update here) when I have access to my lab computer again. Thanks! $\endgroup$ – fiziksboy May 31 '16 at 20:06
  • $\begingroup$ Worked in a new notebook file! Thanks somuch! $\endgroup$ – fiziksboy Jun 1 '16 at 12:18
  • $\begingroup$ @fiziksboy, make ClearAll["Global`*"] a habbit see also How do I clear all user defined symbols?, your welcome! $\endgroup$ – user9660 Jun 1 '16 at 13:06

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