How to create layouts in Julia plotting packages?

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

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?

1 Like

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:

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:

You can see a layouting tutorial for Makie here Layout Tutorial

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

2 Likes

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?

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.

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

1 Like

Kindoff :slight_smile:
I’m a long term developer of GMT, but by far not the main developer. What I did was the 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.

1 Like

For the Plots.jl frontend the documentation is here: Layouts · Plots

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].

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.

1 Like

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

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)

2 Likes

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. :slight_smile: