1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – user9660 Feb 27 '16 at 15:47
  • $\begingroup$ Since you not providing any data, see here Density plot with list data and preferable boundary $\endgroup$ – user9660 Feb 27 '16 at 15:50
  • $\begingroup$ Possible duplicate of: (1), (2), (3). $\endgroup$ – Alexey Popkov Feb 27 '16 at 19:35
  • $\begingroup$ They deal with ContourPlot and RegionPlot, but I need ListDensityPlot only for two explicit regions. $\endgroup$ – ElectroWin Feb 28 '16 at 16:43
  • 1
    $\begingroup$ @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... $\endgroup$ – MarcoB Feb 29 '16 at 15:54
1
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • $\begingroup$ MarcoB, thank you very much, that's exactly what I need! $\endgroup$ – ElectroWin Mar 2 '16 at 17:52
  • $\begingroup$ @ElectroWin Glad it helped! $\endgroup$ – MarcoB Mar 2 '16 at 18:42

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.