# Interpolation of a border between regions in ListDensityPlot

Let's say there is a scalar field dependent on two coordinates {x,y}, so a set {x, y, f}, and I use a ListDensityPlot to plot it:

ListDensityPlot[data,PlotRange->{0.5,1},InterpolationOrder->2]


Here we have two regions, a brown one and yellow one: Now I need a smooth curve which would separate these two regions: Ideally, I would like to extract also this curve to a separate plot. How this problem can be solved for ListDensityPlot? Thank you.

• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Feb 27, 2016 at 15:47
• Since you not providing any data, see here Density plot with list data and preferable boundary
– user9660
Feb 27, 2016 at 15:50
• Possible duplicate of: (1), (2), (3). Feb 27, 2016 at 19:35
• They deal with ContourPlot and RegionPlot, but I need ListDensityPlot only for two explicit regions. Feb 28, 2016 at 16:43
• @ElectroWin What you want is a particular contour line for your data. That is why people suggested that you use e.g. ListContourPlot rather than ListDensityPlot, then extract the contour line from the Graphics object that is generated by that function. But again, if you don't share your data with us, we won't be able to help your with your specific problem... Feb 29, 2016 at 15:54

You could try something like the following using contour extraction from a ListContourPlot.

Generate some noisy data:

data = Flatten[#, 1] &@
Table[
{x, y, CDF[BinormalDistribution, {-x, -y}] + RandomReal[{-0.02, 0.02}]},
{x, -3, 3, 0.1}, {y, -3, 3, 0.1}
];


On that data set, we will do the following:

1. generate a contour plot with a specific desired value for the contour
2. extract the contour line from the plot output
3. aggressively smoothen the line using an exponential moving average
4. overlay it on the contour plot

All of it is wrapped in a Manipulate for convenience of finding the contour value you are actually interested in:

Manipulate[
(* generate contour plot *)
cp = ListContourPlot[
data,
Contours -> {contourvalue},
PlotRange -> All
];

(* extract contour data and smoothen *)
smoothcontour = ExponentialMovingAverage[
First@Cases[Normal@cp, Line[a__] -> a, Infinity],
.1 (* smoothing factor; adjust to taste *)
];

(* overlay the smoothed contour line on the original contour plot *)
Show[
cp,
Graphics[{Thickness[0.01], Red, Dashed, Line@smoothcontour}]
],

(* adjust the min / max values of this range to suit your data *)
{{contourvalue, 0.4}, 0.1, 1, 0.1, Appearance -> "Labeled"}
] • MarcoB, thank you very much, that's exactly what I need! Mar 2, 2016 at 17:52
• @ElectroWin Glad it helped! Mar 2, 2016 at 18:42