Skip to main content

plotting - ListContourPlot interpolation screws up on concave set of data


I want to create ListContourPlots for sets of Data (from a physics simulation) given as Triplets {x, y, f(x, y)}. Certain parameter regions in the x-y-plane are excluded by experiments. The list of triplets simply does not contain any Triplets with excluded x-y-parameters. ListPointPlot3D shows that this is not the problem.



The problem is that ListContourPlot (which I prefer to use, since I have to correlate exclusions from different quantities) interpolates values into regions where no data points are given, as soon as the shape of the data-filled region becomes concave.


I already tried creating a list that is only defined in the excluded regions and painting it over the original plot, however, my dataset is not entirely concave, so that overpainting will cut off some of the interesting parts of the plot...


I figure it has something to do with the "Method" option of ListContourPlot, but those things are really badly documented.


Here is a list of 140 data triplets that show the problem.


l= {{14., 2.1, 125.433}, {14., 2.1375, 125.957}, {14., 2.175, 
126.58}, {14., 2.2125, 127.354}, {14., 2.25, 128.415}, {14.5,
2.1125, 125.698}, {14.5, 2.15, 126.315}, {14.5, 2.1875,
127.087}, {14.5, 2.225, 128.152}, {15., 2.1, 125.593}, {15., 2.1375,
126.238}, {15., 2.175, 127.061}, {15., 2.2125, 128.256}, {15.5,
2.1125, 125.886}, {15.5, 2.15, 126.669}, {15.5, 2.1875,

127.783}, {16., 2.1, 125.73}, {16., 2.1375, 126.534}, {16., 2.175,
127.708}, {16.5, 2.1125, 126.054}, {16.5, 2.15, 127.082}, {17., 2.1,
125.829}, {17., 2.1375, 126.85}, {17.5, 2.1, 125.858}, {17.5,
2.1375, 127.016}, {18., 2.1, 125.868}, {18., 2.1375,
127.185}, {18.5, 2.1125, 126.243}, {18.5, 2.15, 128.277}, {19.,
2.125, 126.76}, {19.5, 2.1125, 126.183}, {20., 2.1, 125.633}, {20.,
2.1375, 127.686}, {20.5, 2.125, 126.573}, {21., 2.1125,
125.763}, {21.5, 2.1, 125.093}, {21.5, 2.1375, 127.062}, {22.,
2.125, 125.806}, {22.5, 2.1125, 124.979}, {22.5, 2.15,
127.707}, {23., 2.125, 125.111}, {23.5, 2.1, 124.03}, {23.5, 2.1375,

125.248}, {24., 2.1, 123.738}, {24., 2.1375, 124.82}, {24.5, 2.1,
123.445}, {24.5, 2.1375, 124.411}, {24.5, 2.175, 126.896}, {25.,
2.125, 123.689}, {25., 2.1625, 124.924}, {25.5, 2.1125,
123.092}, {25.5, 2.15, 123.987}, {25.5, 2.1875, 125.801}, {26.,
2.125, 123.022}, {26., 2.1625, 123.937}, {26., 2.2, 125.892}, {26.5,
2.125, 122.703}, {26.5, 2.1625, 123.512}, {26.5, 2.2,
124.901}, {27., 2.1125, 122.198}, {27., 2.15, 122.848}, {27.,
2.1875, 123.782}, {27., 2.225, 125.874}, {27.5, 2.125,
122.095}, {27.5, 2.1625, 122.745}, {27.5, 2.2, 123.676}, {27.5,
2.2375, 125.734}, {28., 2.125, 121.808}, {28., 2.1625,

122.394}, {28., 2.2, 123.198}, {28., 2.2375, 124.563}, {28.5,
2.1125, 121.39}, {28.5, 2.15, 121.87}, {28.5, 2.1875,
122.506}, {28.5, 2.225, 123.412}, {28.5, 2.2625, 125.253}, {29.,
2.125, 121.29}, {29., 2.1625, 121.747}, {29., 2.2, 122.372}, {29.,
2.2375, 123.256}, {29., 2.275, 124.961}, {29.5, 2.125,
121.036}, {29.5, 2.1625, 121.454}, {29.5, 2.2, 122.006}, {29.5,
2.2375, 122.762}, {29.5, 2.275, 123.966}, {30., 2.1, 120.465}, {30.,
2.1375, 120.896}, {30., 2.175, 121.334}, {30., 2.2125,
121.862}, {30., 2.25, 122.595}, {30., 2.2875, 123.735}, {30.5, 2.1,
120.187}, {30.5, 2.1375, 120.599}, {30.5, 2.175, 121.065}, {30.5,

2.2125, 121.525}, {30.5, 2.25, 122.157}, {30.5, 2.2875,
123.07}, {30.5, 2.325, 124.9}, {31., 2.125, 120.167}, {31., 2.1625,
120.593}, {31., 2.2, 121.078}, {31., 2.2375, 121.561}, {31., 2.275,
122.237}, {31., 2.3125, 123.247}, {31., 2.35, 126.014}, {31.5,
2.125, 119.881}, {31.5, 2.1625, 120.285}, {31.5, 2.2,
120.747}, {31.5, 2.2375, 121.268}, {31.5, 2.275, 121.808}, {31.5,
2.3125, 122.628}, {31.5, 2.35, 124.034}, {32., 2.1125,
119.484}, {32., 2.15, 119.849}, {32., 2.1875, 120.264}, {32., 2.225,
120.742}, {32., 2.2625, 121.268}, {32., 2.3, 121.85}, {32., 2.3375,
122.72}, {32.5, 2.1125, 119.213}, {32.5, 2.15, 119.558}, {32.5,

2.1875, 119.949}, {32.5, 2.225, 120.396}, {32.5, 2.2625,
120.911}, {32.5, 2.3, 121.431}, {33., 2.1, 118.846}, {33., 2.1375,
119.16}, {33., 2.175, 119.512}, {33., 2.2125, 119.91}, {33., 2.25,
120.365}, {33., 2.2875, 120.871}, {33.5, 2.125, 118.783}, {33.5,
2.1625, 119.101}, {33.5, 2.2, 119.458}, {33.5, 2.2375,
119.856}, {34., 2.1, 118.333}, {34., 2.1375, 118.614}, {34., 2.175,
118.923}, {34., 2.2125, 119.261}};

ListPlot@l[[All, 1 ;; 2]]


Mathematica graphics



Answer



f = Interpolation[l3= (Last /@ Sort /@ GatherBy[l[[All, 1 ;; 2]], #[[1]] &])]
ListContourPlot[l, RegionFunction -> (#2 < f[#1] &)]

Mathematica graphics


Edit


If you want a smoother curve, you could use for example whuber's method here for getting something similar to an "envolvent" curve:


l4 = {(#[[1]] - 14) 2 + 1, #[[2]]} & /@ l3;
nrow = 32;

i = Image[SparseArray[Flatten[Table[{i, IntegerPart@#1} -> #2, {i, 1, nrow}] & @@@ l4]]]
// ImageAdjust

Mathematica graphics


{minima, maxima} = Flatten[Position[First[ImageData[#[i]]], 1]] & /@ {MinDetect, MaxDetect};

f1 = Interpolation[N@{(#[[1]] - 1)/2 + 14, #[[2]]} & /@ l4[[maxima]], InterpolationOrder -> 1]

f2[x_] = Max[f[x], f1[x]]


The "envolvent":


Quiet@Show[ListLinePlot@l3, Plot[f2[x], {x, 14, 34}]]

Mathematica graphics


Quiet@ListContourPlot[l, RegionFunction -> (#2 < f2[#1] &)]

Mathematica graphics


Quiet@ListPlot3D[l, RegionFunction -> (#2 < f2[#1] &), 
ColorFunction -> "SouthwestColors", MeshFunctions -> {#3 &}]


Mathematica graphics


Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

calculus and analysis - Integral of the Sinc product

Let us consider the following integral $$ B_n = \int_0^\infty \prod_{k=1,3,5,\dots}^n\frac{\sin (x/k)}{x/k}dx $$ By definition, Sinc[x] == Sin[x]/x , therefore B[n_?OddQ] := Integrate[Product[Sinc[x/k], {k, 1, n, 2}], {x, 0, Infinity}] B /@ Range[1, 13, 2] {Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2} OK, everything is fine. But... B[15] 467807924713440738696537864469 Pi/935615849440640907310521750000 What's going on? Answer As Eckhard wrote in comments B[n] is the n-th Borwein integral . (The letter B was not accidental :) ) This funny properties of Borwein integrals is related to the Fourier transform of Sinc function FourierTransform[Sinc[x], x, k] 1/2 Sqrt[Pi/2] (Sign[1 - k] + Sign[1 + k]) Plot[%, {k, -2, 2}, Filling -> 0] which is the box function. The result is $\pi/2$ while the sum $$ 1/3+1/5+\dots+1/n $$ B_n = \frac{\pi}{2} - \pi \bigg(\sum_{k=3,5,\ldots}^n\frac{1}{k} -1\biggr)^\frac{n-1}{2}\prod_{k=3,5,\dots}^n\frac{k}{k-1}. $$ For $n=15$ it is equal to $$ \frac{46780...

list manipulation - Selecting multiple columns from a matrix?

Sample data: data = { {{2013, 1, 1}, 24.13, 167.67, 231.82}, {{2013, 1, 2}, 32.15, 170.92, 225.99}, {{2013, 1, 3}, 35.43, 172.68, 221.67}, {{2013, 1, 4}, 36.73, 173.05, 218.32}, {{2013, 1, 5}, 58.19, 165.96, 197.05}, {{2013, 1, 6}, 69.99, 163.50, 187.52}, {{2013, 1, 7}, 71.37, 154.21, 175.58}, {{2013, 1, 8}, 72.51, 149.66, 163.25}}; I want a DateListPlot with three graphs, so for a matrix formed by columns 1 and 2, one for columns 1 and 3, and 1 for columns 1 and 4. At the moment I'm using this code: data2 = Transpose[{data[[All, 1]], data[[All, 2]]}]; data3 = Transpose[{data[[All, 1]], data[[All, 3]]}]; data4 = Transpose[{data[[All, 1]], data[[All, 4]]}]; DateListPlot[{data2, data3, data4}, Joined -> True, Filling -> {3 -> {1}}] but I have a hunch that this can be done more efficiently. I don't like the Transpose s in particular. Any ideas? edit (for extra credit) What if I need to multiply the second column by 2, which in my solution is simp...