# Mark size in axis units with PGFPlotsX

**URL:** <https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266>\
**Category:** Visualization\
**Tags:** question, plotting, pgfplotsx\
**Created:** [November 19, 2019, 9:20am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266 "2019-11-19T09:20:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![danscr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danscr/32/11396_2.png) [@danscr](https://discourse.julialang.org/u/danscr)\
**Post date:** [November 19, 2019, 9:20am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/1 "2019-11-19T09:20:45Z")

</div>

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](https://global.discourse-cdn.com/julialang/original/3X/9/8/98b03668a4e19616215c1ad922e9137de1b932d3.png)

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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 19, 2019, 9:52am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/2 "2019-11-19T09:52:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danscr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danscr/32/11396_2.png) [@danscr](https://discourse.julialang.org/u/danscr)\
**Post date:** [November 19, 2019, 10:33am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/3 "2019-11-19T10:33:51Z")

</div>

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.

[https://gist.github.com/danscr/539f0840594b628335f7ebcc5ac19609](https://gist.github.com/danscr/539f0840594b628335f7ebcc5ac19609)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 19, 2019, 10:45am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/4 "2019-11-19T10:45:35Z")

</div>

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

pgfplots has something called “axis units”, not sure if it helps here.

---

<div class="post-metadata">

**Author:** ![danscr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danscr/32/11396_2.png) [@danscr](https://discourse.julialang.org/u/danscr)\
**Post date:** [November 19, 2019, 10:52am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/5 "2019-11-19T10:52:51Z")

</div>

Sorry about that. I updated the gist

---

<div class="post-metadata">

**Author:** ![danscr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danscr/32/11396_2.png) [@danscr](https://discourse.julialang.org/u/danscr)\
**Post date:** [November 19, 2019, 11:28am UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/6 "2019-11-19T11:28:57Z")

</div>

> [@Tamas\_Papp](#):
>
> pgfplots has something called “axis units”, not sure if it helps here.

From the PGFPlots manual ([https://www.texlive.info/CTAN/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf](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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 19, 2019, 12:40pm UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/7 "2019-11-19T12:40:08Z")

</div>

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](https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/gallery.html#Patch-1)

---

<div class="post-metadata">

**Author:** ![danscr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danscr/32/11396_2.png) [@danscr](https://discourse.julialang.org/u/danscr)\
**Post date:** [November 19, 2019, 12:54pm UTC](https://discourse.julialang.org/t/mark-size-in-axis-units-with-pgfplotsx/31266/8 "2019-11-19T12:54:11Z")

</div>

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