2
$\begingroup$

I would like to visualize some 3d data. What I want is similar to

ListPlot3D[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}}, 
 Mesh -> All]

what I dont want

however, the result should look like

what I do want

which is an array plot:

ArrayPlot[RandomReal[1, {10, 20}]]

The crucial difference is, that I would prefer to be able to plot my Data straight away (where z should be colormapped, i.e. 0: black, 1:white).

{{x1, y1, z1}, ... , {xn, yn, zn}}, x_{n+1} - x_{n} != y_{n+1} - y_{n}

It's generated via c++. ideally, i would like to read it out of a HDFS dataspace. Finally, it looks something like this:

{{0.0, 0.0, 0.12343},{0.0,0.1,0.5233},{0.0,0.2,0.86493},{0.0,0.4,0.9854},...},
{0.4, 0.0, 0.45347},{0.4,0.1,0.7231},{0.4,0.2,0.9433},{0.4,0.4,0.7459},...},
{0.8, 0.0, 0.3455},{0.8,0.1,0.3457},{0.8,0.2,0.5422},{0.8,0.4,0.01208},...},
...
{1.2, 0.0, 0.35425},{1.2,0.1,0.68425},{1.2,0.2,0.6546},{1.2,0.4,0.8243},...}}

Of course, I could transform it to

{{a11, a12, ..., a1n}, ... , {am1, am2, ..., amn}}

via

z = data[[All, 3]];
Partition[z, 4];

manually (thanks Okkes), but then, I loose the information of pixel size

(x_{n+1} - x_{n}) x (y_{n+1} - y_{n})

This means, the pixels may be supposed to look non-quadratic.

I have spent some time to find a solution, so any help is much appreciated!

$\endgroup$
5
  • $\begingroup$ Do you need the 3D surface with discrete "pixels" like set of squares at the different altitudes? Just use the InterpolationOrder->0 inside your ListPlot3D if so. $\endgroup$
    – Rom38
    Aug 7, 2018 at 11:27
  • $\begingroup$ thanks, but not really... should really be png-ish in the end. The thing is, that dx may not be equal to dy, otherwise @Okkes answer would work fine $\endgroup$
    – Baedsch
    Aug 7, 2018 at 11:42
  • $\begingroup$ Can you post small portion of your data? How do you generate your data? $\endgroup$ Aug 7, 2018 at 11:46
  • $\begingroup$ Welcome to Mma.SE. Thanks for taking the tour. Be sure you have learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of your code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Aug 7, 2018 at 13:54
  • $\begingroup$ thanks @rhermans, I dont quite understand, what Im doing wrong... $\endgroup$
    – Baedsch
    Aug 7, 2018 at 15:39

2 Answers 2

0
$\begingroup$

Strongly related QA from where I'm borrowing the technique

Caveat: the ordering of the mesh cells is not the same as the ordering of the initial data points. Using some help from this answer I fix this with an undocumented function Region`Mesh`MeshMemberCellIndex.

Let's generate some test data:

data = RandomReal[1, {36, 3}];
mesh = VoronoiMesh[data[[;; , ;; 2]]];
ind = MeshCellIndex[mesh, 2];
ordereddata = 
 data[[Region`Mesh`MeshMemberCellIndex[mesh][
   data[[;; , ;; 2]]][[;; ,2]] // Ordering]]
style = Style @@@ (Transpose@{ind, GrayLevel /@ ordereddata[[;; , 3]]});
HighlightMesh[mesh, {style}]

matrixplot

This method also works for a rectangular grid:

data = Table[{i, j, RandomReal[]}, {i, 0, 5, .4}, {j, 0, 2, .2}] // Flatten[#, 1] &;

rectangular

and it is quite easy to clip the large boundaries like so:

With[{xstep = data[[;; , 1]] // Union // Differences // Min,
  ystep = data[[;; , 2]] // Union // Differences // Min},
 xrange = (data[[;; , 1]] // MinMax) + {-.5, .5} xstep;
 yrange = (data[[;; , 2]] // MinMax) + {-.5, .5} ystep;]
mesh = VoronoiMesh[data[[;; , ;; 2]], {xrange, yrange}];

better

Take care though, the last code snippet has no error checking, so may clip a bit more than desired on an unstructured grid.

$\endgroup$
1
  • $\begingroup$ thanks a lot, this works $\endgroup$
    – Baedsch
    Aug 7, 2018 at 15:37
0
$\begingroup$

Assume your data is in data={{x1, y1, z1}, ... , {xn, yn, zn}} form and you only care about plotting zvalues, then you can do the following. It is up to you how you partition your data.

      SeedRandom@2
data = RandomReal[1, {36, 3}];
z = data[[All, 3]];
Row[{ArrayPlot[Partition[z, 4]], ArrayPlot[Partition[z, 6]], 
  ArrayPlot[Partition[z, 9]]}, Spacer@20]

enter image description here

$\endgroup$
2
  • $\begingroup$ thanks, this kind of does, what it is supposed to, however, I forgot to mention, that dx may not be equal to dy $\endgroup$
    – Baedsch
    Aug 7, 2018 at 11:35
  • $\begingroup$ What do you mean by that? $\endgroup$ Aug 7, 2018 at 12:05

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.