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:
vxl

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
(2) Manually adjusting the size.
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.