# Mark size in axis units with PGFPlotsX

I want to plot a 3d array as a voxel grid (i.e. adjacent cubes of equal size) with PGFPlotsX.
So far I got a simple solution using a 3d scatterplot with filled cubes of separate color, depending on the array value.
The challenge is to get the size right so that each cube is adjacent to its neighbors, as shown here:

Is there a way to define the mark size of 3d scatterplots in the same unit as the axes?

Can you post an MWE of what you have done so far, and perhaps a link to the source of the plot above?

Below is an MWE. I have so far tried two ways to control the cube size:
(1) Controlling width and height of the figure and setting cube size in absolute units, and
Attempt (1) seems unsuitable because with different view direction on the 3D axis the scale of the figure changes slightly.
And with (2) I could get some nice looking results, but this approach doesnâ€™t scale.

Please post an MWE that actually works, here `Î›` is not defined.

pgfplots has something called â€śaxis unitsâ€ť, not sure if it helps here.

Sorry about that. I updated the gist

From the PGFPlots manual (https://www.texlive.info/CTAN/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf, p. 275):

Shifting by axis units is only possible for two-dimensional plots since the outer normal is well-defined here: it is the other available axis.

This seems to concern only line shifts, but as far as I understood this axis units are defined by leaving out any dimension in the size argument, which didnâ€™t work for my case in 3D either.

If you want total control over the cubes using axis coordinates, look up â€śpatch plotsâ€ť in the pgfplots manual. We have a rudimentary example in PGFPlotsX to get you started:

https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/gallery.html#Patch-1

1 Like

Thanks! This really seems to best way to do it.