1

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: enter image description here Now I need a smooth curve which would separate these two regions: enter image description here Ideally, I would like to extract also this curve to a separate plot. How this problem can be solved for ListDensityPlot? Thank you.

ElectroWin
  • 13
  • 2

1 Answers1

1

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[0], {-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"}
]

Mathematica graphics

MarcoB
  • 67,153
  • 18
  • 91
  • 189