2
$\begingroup$

I'm still unsuccessfully trying to use ContourPlot:

 data = Import["http://pastebin.com/raw/sEYmMN96", "Package"];
 ListContourPlot[data, InterpolationOrder -> 3]

The result is this:

enter image description here

But when I ListPointPlot3d[data] it lies on a very nice surface the contours of which should be smooth and easy to find:

enter image description here

I've tried sampling more densely and it is still very jaggered. And unlike last time, my data points are regular. Am I misunderstanding how to use something, or is this just a little broken?

$\endgroup$
4
$\begingroup$

The method I just used in ContourPlot interpolation woes also works here:

data = Import["http://pastebin.com/raw/sEYmMN96", "Package"];
{nrows, ncols} = SplitBy[data, First] // Dimensions // Most
(*  {10, 10}  *)

Needs["NDSolve`FEM`"];

emesh = ToElementMesh[
   "Coordinates" -> N@data[[All, {1, 2}]],
   "MeshElements" -> {QuadElement[Flatten[
       Table[
        i + ncols j + {0, ncols, ncols + 1, 1},
        {j, 0, nrows - 2}, {i, ncols - 1}],
       1]]}
   ];

if = ElementMeshInterpolation[{emesh}, data[[All, 3]]];

ElementMeshContourPlot[if]

Mathematica graphics

So it might be considered a duplicate, I think.

$\endgroup$
  • 1
    $\begingroup$ Nice - it also works without ExtrapolationHandler... there seem to be no warnings. $\endgroup$ – Jens Sep 18 '16 at 22:03
  • $\begingroup$ @Jens Thanks. "ExtrapolationHandler" is from some earlier permutation that did give a warning. $\endgroup$ – Michael E2 Sep 18 '16 at 22:08
5
$\begingroup$

You can see the structure of the data also in other ways:

ListDensityPlot[data, PlotLegends -> Automatic]

enter image description here


This illustrates that quite independent on the InterpolationOrder the same points are used to construct a ListContourPlot:

ListContourPlot[data, InterpolationOrder -> 100, Mesh -> All]

enter image description here

However, you can play with MaxPlotPoints and try to achieve the desired result:

ListContourPlot[data, MaxPlotPoints -> 12]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks Corey. The first two images just seem to show the same problem for other display kinds. But I the last method looks promising. I'm going to try a higher sample rate with that and see if it's good enough. $\endgroup$ – bjorne Sep 18 '16 at 20:32
4
$\begingroup$

Let's look at the data in a different way:

ListPlot3D[data, InterpolationOrder -> 0, PlotRange -> All, 
 Filling -> Bottom, FillingStyle -> Directive[Opacity[1], Blue]]

ambiguity

You can see a staircase going up from left to right in the back. But right below that is a flat bottom. So there is not enough information to draw contours of intermediate height in that region. You'd have to select contours that you know are connected to sufficiently many points in your data.

Otherwise, I'd suggest fitting the data to a continuous model function first, and then plotting that.

Edit

For future reference, it may one day be possible to steer the contour interpolation with a Method option, as pointed out in this question by JasonB. Unfortunately, at this point there currently seems to be no information about the possible Method options that could help here.

$\endgroup$
  • $\begingroup$ Thanks Jens. I don't think I quite see the problem. If the interpolant is zeroth order then I understand my jaggered picture, but for higher orders I don't see the problem with extracting a level-set/contour that isn't on the block edges. I like the idea of fitting to a smooth function, but in general I don't know the function form. I will try with a general interpolant, but I think that's what ContourPlot already does, no? $\endgroup$ – bjorne Sep 18 '16 at 19:00
  • $\begingroup$ It's true that this jagged appearance isn't an unavoidable consequence of the lack of data. But in the absence of any Method option my only conclusion is that more data would be the best way to remedy the issue right now... it's quite weird that ListPlot3D lists Method as one of its options, but there is no documentation on it. $\endgroup$ – Jens Sep 18 '16 at 21:59
  • $\begingroup$ For the record, ContourPlot of an InterpolatingFunction was quite fast and much better than what I had, but I've accepted the Michael's answer since the final result was superior. $\endgroup$ – bjorne Sep 18 '16 at 22:13

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.