I'm trying to make a ContourPlot of a set of data of the kind: $(x,y,f(x,y))$

What I'd like to do is to remove the majority of the iso-line and just leave two of them, but keeping the changing of the color.

In other words I'd like to obtain something like a ListDensityPlot of my data set, but with two iso-curves marking the points $(x,y)$ having either value $0$ or $-0.0005$.

Any idea on how to do this? like for example overlapping two different graphs on each other or extracting the iso-curve interpolant from the contour plot and plug it into the density plot? these are just some ideas...

  • $\begingroup$ "ContourStyle → $\{g_1, g_2, \ldots\}$ specifies that successive directives $g_i$ should be used to draw successive contours." So, for example, Contours -> {0, 0.1, 0.2, 0.5}, ContourStyle -> {Black, None, None, Black}. $\endgroup$
    – user484
    Dec 31, 2014 at 18:11
  • $\begingroup$ You could also Show a ListContourPlot with just the contours you want (and ContourShading -> None) on top of a ListDensityPlot. $\endgroup$
    – user484
    Dec 31, 2014 at 18:14
  • $\begingroup$ this seems a very nice idea! $\endgroup$
    – SSC Napoli
    Dec 31, 2014 at 18:17

1 Answer 1

data = Table[Sin[i + j^2], {i, 0, 3, 0.05}, {j, 0, 3, 0.05}];

ListContourPlot[data, ColorFunction -> "Rainbow", 
 Contours -> {{0, {Thick, Black}}, {-.5, {Thick, Dashed, Black}}, 
               Sequence @@ ({#, None} & /@ Range[Min@data, Max@data, .0025])}]

enter image description here

You can also use the desired contours as Epilog with ListDensityPlot:

lcp = ListContourPlot[data, ContourShading -> None,
   Contours -> {{0, {Thick, Black}}, {-.5, {Thick, Dashed, Black}}}];
ListDensityPlot[data, ColorFunction -> "Rainbow", Epilog -> lcp[[1]]]

enter image description here

Or, to use default contour styles, use Contours -> {0, -.5} in lcp to get

ListDensityPlot[data, ColorFunction -> "Rainbow", Epilog -> lcp[[1]]]

enter image description here

Update: You can also use Mesh and MeshFunctions with ListDensityPlot:

ListDensityPlot[data, ColorFunction -> "Rainbow", MeshFunctions -> {#3 &},  Mesh -> {{0., -.5}}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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