2
$\begingroup$

I am trying to fit a list {{x1,y1,f1},{x2,y2,f2},...} with ListDensityPlot. The tricky part is that for a fixed x, the list does not have the same step size in y. I would like to not interpolate the plot, but when I use InterpolationOrder -> 0, the plot fixes data range to the maximum value.

Here is an example to illustrate it

ListDensityPlot[{
{1, 1, 3}, {1, 2, 4}, {1, 3, 4},
{2, 0.5, 1}, {2, 2, 2}, {2, 3.5, 5},
{3, 0.75, 2}, {3, 2, 1}, {3, 3.25, 0}
}]

which yields

enter image description here

Adding InterpolationOrder->0 results in

ListDensityPlot[{{1, 1, 3}, {1, 2, 4}, {1, 3, 4}, {2, 0.5, 1}, {2, 2, 
   2}, {2, 3.5, 5}, {3, 0.75, 2}, {3, 2, 1}, {3, 3.25, 0}}, 
 InterpolationOrder -> 0]

enter image description here

Is there an easy way to not interpolate the data, but also avoid getting it distorted?

Thanks, Sole

$\endgroup$
2
  • $\begingroup$ Could you clarify what you mean by distortion in this case? $\endgroup$
    – MarcoB
    Jun 4, 2018 at 22:52
  • $\begingroup$ Well, for example, the data point at {1,3} gets pushed to {1,3.5} when using InterpolationOrder->0, which is not a true coordinate of that data point. $\endgroup$
    – sole
    Jun 5, 2018 at 22:20

1 Answer 1

4
$\begingroup$

Do you mean this?

pts = {{1, 1, 3}, {1, 2, 4}, {1, 3, 4}, {2, 0.5, 1}, {2, 2, 2}, {2, 
    3.5, 5}, {3, 0.75, 2}, {3, 2, 1}, {3, 3.25, 0}};
R = ConvexHullMesh[pts[[All, 1 ;; 2]]];
ListDensityPlot[pts,
 InterpolationOrder -> 0,
 RegionFunction -> ({x, y, z} \[Function] RegionMember[R][{x, y}])
 ]

enter image description here

Note that ListDensityPlot colors always full Voronoi cells with respect to the point cloud pts. That actually quite meaningful.

$\endgroup$
0

Your Answer

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

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