4
$\begingroup$

I have data = {{x,y,z},...};, which I have posted here and when I ContourPlot in the following way,

data = Import["http://pastebin.com/raw/zHhaM4cb", "Package"];

ListContourPlot[data, PlotRange -> {0, 10}, Mesh -> All, Contours -> Range[0, 10],  PerformanceGoal -> "Quality", ImageSize -> {500, 500}]

I get,

enter image description here

There are a few problems here. The dark blue bits jutting out the bottom is Mathematica trying to connect the values at the cusp to the rest of the zero values (I think). I can get rid of that with RegionFunction so let's ignore that.

The main problem is the corners along the top edge. The data is sampled at thirty points along the x axis, and for each point, there are twelve y values where the function height/value is 0, 1, ..., 10, 10+, where the last number is something larger than 10 - I don't think it's important because I've restricted the range to 10. These points are essentially the points of intersection of the mesh drawn in the picture. They're all there. The interpolation on the right-hand side looks perfect, and then as we move left the interpolation (or something else) goes awry.

I'm a bit stuck!? This is also causing the ListPlot3D to have unwanted ridges. Is there an interpolation option I can choose that will make this better? Or do I just have to sample more densely along the x-axis?

$\endgroup$
4
  • 1
    $\begingroup$ I don't think you necessarily want to sample more densely along either axis (although that's always helpful), what you need to do is sample the points on a regular grid if you can. The interpolation algorithms just work so much better if you sample on a grid. Then, feed ListContourPlot your data as an array of z values. See here and here for examples of that behavior. $\endgroup$
    – Jason B.
    Sep 16, 2016 at 13:30
  • $\begingroup$ @JasonB, very interesting (although slightly ararming) results. The problem with a regular grid is the shape of the region of interest is a cusp. So to have, say, 10 sampling points in the region of interest in the y direction, means the points need to be separated by a tiny amount, which will make this plot enormous! $\endgroup$
    – bjorne
    Sep 16, 2016 at 13:50
  • $\begingroup$ @bjorne Consider making a change of variables (transform the domain to a rectangle, plot, transform back)....I did something like it on this site before. Maybe I can find it. $\endgroup$
    – Michael E2
    Sep 16, 2016 at 16:04
  • $\begingroup$ Somewhat related, but not based on data: mathematica.stackexchange.com/a/85922/4999 $\endgroup$
    – Michael E2
    Sep 16, 2016 at 16:10

1 Answer 1

4
$\begingroup$

Your data has a what we might call a "perturbed" or "nonlinear" 29 x 12 tensor-grid structure. So it's relatively easy to mesh the domain by hand.

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

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, Contours -> Range[0, 10]]

Mathematica graphics

Style as you wish. ElementMeshContourPlot seems to have the most of the same options as ContourPlot.

$\endgroup$
1
  • $\begingroup$ Wow. This looks amazing! I ended up working around it by Ploting the contours by hand and using Filling, which produces almost the exact same image, but this is closer to the original! Not really sure what this is actually doing, but I will investigate. Thanks! $\endgroup$
    – bjorne
    Sep 18, 2016 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.