# ContourPlot Woes II

I'm still unsuccessfully trying to use ContourPlot:

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


The result is this:

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

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?

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["NDSolveFEM"];

emesh = ToElementMesh[
"Coordinates" -> N@data[[All, {1, 2}]],
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]


So it might be considered a duplicate, I think.

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

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

ListDensityPlot[data, PlotLegends -> Automatic]


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

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


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

ListContourPlot[data, MaxPlotPoints -> 12]


• 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. – bjorne Sep 18 '16 at 20:32

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

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


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.

• 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? – bjorne Sep 18 '16 at 19:00
• 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. – Jens Sep 18 '16 at 21:59
• 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. – bjorne Sep 18 '16 at 22:13