# How to create layouts in Julia plotting packages?

**URL:** <https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586>\
**Category:** Visualization\
**Tags:** question\
**Created:** [October 29, 2021, 12:54am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586 "2021-10-29T00:54:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 29, 2021, 12:54am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/1 "2021-10-29T00:54:12Z")

</div>

As a Matlab person, I’m so attached to the thinking as below:

```julia
Handle = figure(1);                  
% creating a figure handle

Han01 = subplot(2, 2, 1);    
% creating a subplot handle (1st out of a total of 2x2 subplots)

plot...                                       
% plot something. This can be anything like a contour, scatter, etc.

Han02 = subplot(2, 2, 2);    
% creating a 2nd subplot handle

plot ...                                      
% plot the 2nd item.

set(Handle, 'position', ...);        
% set the position and size of the overall figure.

set(Han01, 'position', ...);         
% set the relative position and size of each subplots within the figure.

```

It seems that Julia does not even use a figure or subplot handle? How do I set their size and their relative position?

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [October 29, 2021, 4:07am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/2 "2021-10-29T04:07:36Z")

</div>

I would appreciate an explanation of what does each command mean for those not familiar with matlab.

Julia by itself doesn’t plot, so you first must pick one of the different plotting packages and then we can discuss how to use them. Some that come to mind are Makie.jl, Plots.jl, GR.jl, PyPlot.jl, Gadfly.jl and VegaLite.jl.

For example, in Makie, you could do something like:

```julia
using GLMakie
fig = Figure()
ax = Axis(fig[1,1]) #create an axis in positiion 1,1
lines!(ax,rand(10),rand(10)) # plot a line into that axis
ax2 = Axis(fig[1,2]) #create new axis, now in position 1,2
scatter!(ax2,rand(10),rand(10)) #do a scatter line in the second axis

```

And this will give you something like:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4c77e368160028997a090c80766fbb0dab789c0.png)

You can see a layouting tutorial for Makie here [Layout Tutorial](https://makie.juliaplots.org/stable/tutorials/layout-tutorial/)

For other packages, the syntax and layouting will be different.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 29, 2021, 4:41am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/3 "2021-10-29T04:41:38Z")

</div>

Many thanks for the reply!

- I have updated the original post to add comments explaining each line of the Matlab example code
- The package I’m using is `GMT.jl`

It’s great to see the GLMakie example. The layout approach is actually very much like those of Matlab. On the other hand, I’m a little surprised to hear that this layout thing is package specific. I assume Julia would also allow me to plot different things in each of the layouts? For example, I could plot an x-y plot in subplot1, a scatter plot in subplot2, a mapping plot in subplot3, and a contour plot in subplot4?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 29, 2021, 5:58am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/4 "2021-10-29T05:58:17Z")

</div>

Julia doesn’t have a central plotting engine like R or Matlab that other packages build on top of. So that makes every plotting package different. Naturally, that includes how layouts are handled.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [October 29, 2021, 3:16pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/5 "2021-10-29T15:16:13Z")

</div>

I think @joa-quim is the author of the GMT package

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 29, 2021, 3:46pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/6 "2021-10-29T15:46:22Z")

</div>

_Kindoff_ 🙂  
I’m a long term developer of [GMT](https://www.generic-mapping-tools.org/), but by far not the main developer. What I did was the [GMT.jl](https://github.com/GenericMappingTools/GMT.jl) wrapper.

@leon Like jules told you, you cannot expect to find the same situation in Julia as in Matlab (I’m also a _Matlaber_). Here you several different options, for bad and for good.  
You can produce similar figure as above in GMT.jl if you use the `subplot` module.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 29, 2021, 5:09pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/7 "2021-10-29T17:09:01Z")

</div>

For the Plots.jl frontend the documentation is here: [Layouts · Plots](https://docs.juliaplots.org/latest/layouts/)

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [October 29, 2021, 8:12pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/8 "2021-10-29T20:12:04Z")

</div>

In Gadfly, I do layouts with the use of Gadfly.Geom.subplot\_grid or stacks (hstack, vstack, gridstack) [[http://gadflyjl.org/stable/man/compositing/#Compositing](http://gadflyjl.org/stable/man/compositing/#Compositing)].

> [@leon](#):
>
> I’m a little surprised to hear that this layout thing is package specific. I assume Julia would also allow me to plot different things in each of the layouts?

I think that you are right that the workflow might be more complicated if one wants to combine plots from different packages, especially in vector quality. I guess that in case of raster images Makie has the function to include another image (raster) inside its figure. I guess that GMT might have similar option wrt vectors as it supports postscript. This is just an assumption as I know very little about this mapping package.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 29, 2021, 8:23pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/9 "2021-10-29T20:23:06Z")

</div>

It seems that Julia needs a package-insensitive plotting framework for such layouts.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 29, 2021, 11:06pm UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/10 "2021-10-29T23:06:10Z")

</div>

Why? Just choose one plotting package. I use the default Plots (which uses the GR backend) always and that’s it. (And the other options are on sight always because they may provide cool stuff)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 30, 2021, 12:12am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/11 "2021-10-30T00:12:18Z")

</div>

> [@j\_u](#):
>
> I guess that in case of raster images Makie has the function to include another image (raster) inside its figure. I guess that GMT might have similar option wrt vectors as it supports postscript.

Yes, see the `image` module (It has a kind-off weird name now since it dropped the `ps` from the original `psimage` name)

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [October 30, 2021, 1:57am UTC](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/12 "2021-10-30T01:57:39Z")

</div>

> [@joa-quim](#):
>
> Yes, see the `image` module (It has a kind-off weird name now since it dropped the `ps` from the original `psimage` name)

Your package seems to be so versatile that I am surprised that it is not written in assembly. This is with a big smile. 🙂
