# Multiple plots: some refinements

**URL:** <https://discourse.julialang.org/t/multiple-plots-some-refinements/64800>\
**Category:** Visualization\
**Tags:** graphics, plots, gr, makie\
**Created:** [July 17, 2021, 8:30am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800 "2021-07-17T08:30:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 17, 2021, 8:30am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/1 "2021-07-17T08:30:30Z")

</div>

Hi to everybody,  
I am trying to make some plots for my research (Fisher contour plots) using Plots.jl. I am quite satisfied with the results I have obtained (in a very short amount of time!)

```julia
FisherMatrix = [16523.02 3319.2230;3319.2230 711.09] #Fisher matrix used in the MWE
CovarianceMatrix = inv(FisherMatrix)
σw0 = sqrt(CovarianceMatrix[1,1])
σwa = sqrt(CovarianceMatrix[2,2])
σw0wa = (CovarianceMatrix[1,2])
plot_font = "Computer Modern"

Plots.default(titlefont = (16, plot_font), fontfamily=plot_font, linewidth=1, framestyle=:box, fg_legend =:black, label=nothing, grid=false, tickfontsize=12, size = (600, 500), labelfontsize = 15, dpi = 100)

#Needed for normalization
function gaussian(μ::Float64, σ::Float64, x)
    return 1/(sqrt(2π*σ^2))*exp(-0.5*(x-μ)^2/σ^2)
end

#Drawing ellipses
t = LinRange(0,2π, 200)
θ = 0.01*atan(2σw0wa/(σw0^2-σwa^2))/2#the 0.0
a = (σw0^2+σwa^2)/2+sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
b = (σw0^2+σwa^2)/2-sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
x = a .* cos.(θ) .* cos.(t) - b .* sin.(θ) .* sin.(t)
y = a .* sin.(θ) .* cos.(t) + b .* cos.(θ) .* sin.(t)
p_ell = Plots.plot(x, y, linewidth = 1, legend = false, fill = (0, 0.5, :red),color="red")
Plots.plot!(3x, 3y, linewidth = 1, legend = false, fill = (0, 0.5, :red), xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(-3b,stop=3b,length = 3),digits=4), xlim=(-4a,4a), ylim=(-4b,4b), color="red", ylabel = L"w_a", xlabel = L"w_0")

x = Array(LinRange(-4a,4a, 200))
pwa = Plots.plot(x, gaussian.(0., a, x)./gaussian.(0., a, 0), fill=(0, .5,:red), legend = false, xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(0,stop=1,length=2),digits=2), color="red")
x = Array(LinRange(-a,a, 200))
Plots.plot!(pwa, x, gaussian.(0., a, x)./gaussian.(0., a, 0), fill=(0, .5,:red), legend = false, xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(0,stop=1,length=2),digits=2), color="red", ylabel = L"w_0")

x = Array(LinRange(-4b,4b, 200))
pw0 = Plots.plot(x, gaussian.(0., b, x) ./gaussian.(0., b, 0.), fill=(0, .5,:red), legend = false, xticks = round.(range(-3b,stop=3b,length = 3),digits=4), yticks = round.(range(0,stop=1,length = 2)),figsize=(10,10), color="red")
x = Array(LinRange(-b,b, 200))
Plots.plot!(pw0, x, gaussian.(0., b, x) ./gaussian.(0., b, 0.), fill=(0, .5,:red), legend = false, xticks = round.(range(-3b,stop=3b,length = 3),digits=4), yticks = round.(range(0,stop=1,length = 2)),figsize=(10,10), color="red", xlabel = L"w_a", ymirror=true,)

p_contour = Plots.plot(pwa, emptyplot(), p_ell, pw0, layout = (2, 2), link =:both)

```

![plot](https://global.discourse-cdn.com/julialang/original/3X/9/6/96930e40d16a9a45c383a596bd52b8dcea1550cd.png)  
The result is nice, but I would like to add a couple of things.

1. Whitespace: can I reduce/remove the white space between the subplots?
2. Legend: I’d like to set a single legend for all the plots (possibly in the top right corner)

I’d like to obtain something such as this, obtained with matplotlib

 ![Screenshot from 2021-07-17 10-28-03](https://global.discourse-cdn.com/julialang/original/3X/4/e/4ecf55cac940a53f7bd07af632d2aa57d8ea26d4.png)

Do youhave any suggestion? Any other Julia plot library I could use?  
Best regards,  
Marco

---

<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:** [July 17, 2021, 8:57am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/2 "2021-07-17T08:57:23Z")

</div>

Yes it’s quite simple to do this kind of layout in Makie, you should have no whitespace issues and can place the legend wherever you like.

For starters, have a look at legends here [http://makie.juliaplots.org/stable/makielayout/legend.html](http://makie.juliaplots.org/stable/makielayout/legend.html) and at general layouting here [http://makie.juliaplots.org/stable/makielayout/tutorial.html](http://makie.juliaplots.org/stable/makielayout/tutorial.html)

I don’t have time right now to do an example but your request should be easily manageable with those references.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 17, 2021, 10:05am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/3 "2021-07-17T10:05:57Z")

</div>

```julia
using CairoMakie 
fig = Figure(; resolution = (700, 700))
ax1 = Axis(fig, ylabel = "y")
ax2 = Axis(fig, xlabel = "x", ylabel = "y")
ax3 = Axis(fig, xlabel = "x", yaxisposition =:right)
pltobj1 = lines!(ax1, rand(10), rand(10), color = :red)
pltobj2 = lines!(ax2, rand(10), rand(10))
pltobt3 = lines!(ax3, rand(10), rand(10), color = :black)
leg = Legend(fig, [pltobj1, pltobj2, pltobt3], ["one", "two", "three"], 
    tellheight = false, tellwidth = false, halign = :left, valign = :top, 
    framecolor = :orange)
fig[1,1] = ax1
fig[2,1] = ax2 
fig[2,2] = ax3
fig[1,2] = leg 
colsize!(fig.layout, 1, Relative(1/2))
rowsize!(fig.layout, 1, Relative(1/2))
fig
save("layout4.png", fig, px_per_unit = 2)

```

 ![layout4](https://global.discourse-cdn.com/julialang/original/3X/5/9/5968e3f7bd12b82eb73494eb301301961db58a7e.png)

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 17, 2021, 12:37pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/4 "2021-07-17T12:37:18Z")

</div>

Thank you all.  
After your suggestions, I tried using Makie.  
Here is the result!

 ![contour](https://global.discourse-cdn.com/julialang/original/3X/8/f/8fe9586fe3ddcbb4beca04febef8051113a1eef3.png)

I am quite satisfied. There are a couple of minor issues I should be able to solve by myself (set number of ticks, put ticks on the lower right plot on the right y side). I am more concerned about Latex. I want to use it and it looks that it requires [MakieTex.jl](https://github.com/JuliaPlots/MakieTeX.jl).  
Thank you again!

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 17, 2021, 2:59pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/5 "2021-07-17T14:59:50Z")

</div>

The following examples are not exactly what you want, but may give you many hints.

**Plots.jl examples**

Jupyter notebook: [https://github.com/genkuroki/public/blob/main/0012/marginal%20plots.ipynb](https://github.com/genkuroki/public/blob/main/0012/marginal%20plots.ipynb)

```julia
using Plots
using Distributions
using KernelDensity

# generate test sample
dist_true = MvNormal([1.0, 2.0], [2.0 -1.0; -1.0 4.0])
n = 2^10
sample = rand(dist_true, n)

# kernel density estimation
X, Y = sample[1, :], sample[2, :]
k, kx, ky = kde.(((X, Y), X, Y))
ik, ikx, iky = InterpKDE.((k, kx, ky));

```

**Example 1**

```julia
layout = @layout [
    a _
    b{0.8w, 0.8h} c
]

xlim, ylim = extrema.((k.x, k.y))
legend = colorbar = false
a = plot(kx.x, kx.density; xlim, legend)
c = plot(ky.density, ky.x; ylim, legend, xrotation=90)
b = contour(k.x, k.y, k.density; xlim, ylim, legend)

plot(a, b, c; layout, link=:both, size=(500, 500))

```

![2021-07-17 (0)](https://global.discourse-cdn.com/julialang/original/3X/9/e/9e172c9a59ef56577f31bbf822eb57f23d130282.png)

**Example 2**

```julia
layout = @layout [
    a _
    b{0.8w, 0.8h} c
]

xlim, ylim = extrema.((k.x, k.y))
legend = colorbar = false
a = plot(kx.x, kx.density; xlim, legend)
c = plot(ky.density, ky.x; ylim, legend, xrotation=90)
b = heatmap(k.x, k.y, k.density; xlim, ylim, legend)

plot(a, b, c; layout, link=:both, size=(500, 500))

```

![2021-07-17 (1)](https://global.discourse-cdn.com/julialang/original/3X/c/a/caff23b37ae862e6fb48539fd7001cb32609ee44.png)

**Example 3**

```julia
layout = @layout [
    a _
    b{0.8w, 0.8h} c
]

xlim, ylim = extrema.((k.x, k.y))
legend = colorbar = false
a = plot(kx.x, kx.density; xlim, legend)
c = plot(ky.density, ky.x; ylim, legend, xrotation=90)
b = scatter(X, Y; xlim, ylim, legend, marker_z=pdf.(Ref(ik), X, Y), alpha=0.7, msw=0)

plot(a, b, c; layout, link=:both, size=(500, 500))

```

 ![2021-07-17 (2)](https://global.discourse-cdn.com/julialang/original/3X/4/b/4bfc06645cb7b02541e019f4c4bed184e3c5fb04.png)

**Example 4** (Only color is changed)

```julia
layout = @layout [
    a _
    b{0.8w, 0.8h} c
]

xlim, ylim = extrema.((k.x, k.y))
legend = colorbar = false
a = plot(kx.x, kx.density; xlim, legend)
c = plot(ky.density, ky.x; ylim, legend, xrotation=90)
b = scatter(X, Y; xlim, ylim, legend, marker_z=pdf.(Ref(ik), X, Y), alpha=0.7, msw=0, color=:rainbow)

plot(a, b, c; layout, link=:both, size=(500, 500))

```

 ![2021-07-17 (3)](https://global.discourse-cdn.com/julialang/original/3X/e/b/eb8c8d9134322e14a9158c1a6176ca5bcfd224be.png)

Edit: Jupyter notebook is added.

---

<div class="post-metadata">

**Author:** ![drhouse82](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drhouse82/32/9806_2.png) [@drhouse82](https://discourse.julialang.org/u/drhouse82)\
**Post date:** [July 18, 2021, 9:54am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/6 "2021-07-18T09:54:36Z")

</div>

As far as I understand, LaTeX labels are now included in Make 0.15.

> [@\[ANN\] Makie.jl 0.15](https://discourse.julialang.org/t/ann-makie-jl-0-15/64704):
>
> I’m happy to announce a new, minor Makie version! The main breaking change is described in this [PR](https://github.com/JuliaPlots/Makie.jl/pull/1075). You can find all the other important changes in the [NEWS.md](https://makie.juliaplots.org/stable/news.html). The most exciting feature surely is the much improved LaTex support, thanks to @Kolaru @jules: using CairoMakie f = Figure() ax = Axis(f[1, 1]) lines!(0..10, x -\> sin(3x) / (cos(x) + 2), label = L"\frac{\sin(3x)}{\cos(x) + 2}") lines!(0..10, x -\> sin(x^2) / (cos(sqrt(x)) + 2), label = L"\frac{\sin(x^2)}{\cos(\sqrt{x}) + 2}"…

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 18, 2021, 1:45pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/7 "2021-07-18T13:45:15Z")

</div>

Following your suggestions, I have used `Makie`, obtaining the following result

 ![contour](https://global.discourse-cdn.com/julialang/original/3X/e/9/e98a5e2eab51b7609f6c9ba35f84e88ee79c103c.png)

> **Code (not yet polished)**
>
> ```julia
> c = [16523.02 3319.2230;3319.2230 711.09]
> invc = inv(c)
> σw0 = sqrt(invc[1,1])
> σwa = sqrt(invc[2,2])
> σw0wa = (invc[1,2])
> 
> function my_gaussian(μ::Float64, σ::Float64, x)
> return 1/(sqrt(2π*σ^2))*exp(-0.5*(x-μ)^2/σ^2)
> end
> fig = CairoMakie.Figure(resolution = (1100, 1000), textsize = 32);
> t = LinRange(0,2π, 200)
> 
> θ = 0.01*atan(2σw0wa/(σw0^2-σwa^2))/2
> a = (σw0^2+σwa^2)/2+sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
> b = (σw0^2+σwa^2)/2-sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
> 
> x = a .* cos.(θ) .* cos.(t) - b .* sin.(θ) .* sin.(t)
> y = a .* sin.(θ) .* cos.(t) + b .* cos.(θ) .* sin.(t)
> 
> dimticklabel = 36
> 
> ax2 = fig[1, 1] = Axis(fig , labelsize=50, xticklabelsize = dimticklabel,yaxisposition = (:right), yticklabelsize = dimticklabel, aspect = AxisAspect(1), ylabel = L"P/P_{max}", ylabelsize = 39, yticks = ([0,1], [L"%$i" for i in 0:1]))
> 
> ax1 = fig[2, 1] = Axis(fig, xticklabelsize = dimticklabel, yticklabelsize = dimticklabel, aspect = AxisAspect(1), xlabel = L"w_a",
> ylabel = L"w_0", ylabelsize = 39, xlabelsize = 39, yticks = ([-3b, 0, 3b], [L"%$i" for i in round.(-3b:3b:3b, digits = 4)]), xticks = ([-3a, 0, 3a], [L"%$i" for i in round.(-3a:3a:3a, digits = 2)]))
> 
> ax3 = fig[2, 2] = Axis(fig, yaxisposition = (:right), xticklabelsize = dimticklabel, yticklabelsize = dimticklabel, aspect = AxisAspect(1), xlabel = L"w_0", xlabelsize = 39, xticks = ([-3b, 0, 3b], [L"%$i" for i in round.(-3b:3b:3b, digits = 4)]),ylabelsize = 39, yticks = ([0,1], [L"%$i" for i in 0:1]),ylabel = L"P/P_{max}")
> 
> CairoMakie.lines!(ax1, x, y, color = "red" )
> CairoMakie.lines!(ax1, 3x, 3y, color = "red")
> 
> band!(ax1, x, 0, y , color=("red", 1.0))
> band!(ax1, 3x, 0, 3y , color=("red", 0.5))
> 
> x = Array(LinRange(-4a,4a, 200))
> CairoMakie.lines!(ax2, x, my_gaussian.(0., a, x)./my_gaussian.(0., a, 0), color = "red")
> band!(ax2, x, 0, my_gaussian.(0., a, x)./my_gaussian.(0., a, 0) , color=("red", 0.5), textsize = 32)
> x = Array(LinRange(-1a,1a, 200))
> pltobj1 = band!(ax2, x, 0, my_gaussian.(0., a, x)./my_gaussian.(0., a, 0) , color=("red", 1.0))
> 
> x = Array(LinRange(-4b,4b, 200))
> CairoMakie.lines!(ax3, x, my_gaussian.(0., b, x)./my_gaussian.(0., b, 0), color = "red")
> band!(ax3, x, 0, my_gaussian.(0., b, x)./my_gaussian.(0., b, 0) , color=("red", 0.5))
> x = Array(LinRange(-1b,1b, 200))
> band!(ax3, x, 0, my_gaussian.(0., b, x)./my_gaussian.(0., b, 0) , color=("red", 1.0))
> 
> ax2.xticks = -3a:3a:3a
> 
> linkxaxes!(ax1, ax2)
> leg = Legend(fig, [pltobj1], ["WL"], 
> tellheight = false, tellwidth = false, halign = :right, valign = :top, 
> framecolor = :black, labelsize =32)
> fig[1,2] = leg
> 
> hidexdecorations!(ax2, ticks = false, ticklabels = true, label = false)
> hideydecorations!(ax2, ticks = false, ticklabels = false, label = false)
> hidexdecorations!(ax3, ticks = false, ticklabels = false, label = false)
> hideydecorations!(ax3, ticks = false, ticklabels = false, label = false)
> hidexdecorations!(ax1, ticks = false, ticklabels = false, label = false)
> hideydecorations!(ax1, ticks = false, ticklabels = false, label = false)
> 
> colsize!(fig.layout, 1, Relative(0.5))
> rowsize!(fig.layout, 1, Relative(0.5))
> colsize!(fig.layout, 2, Relative(0.5))
> rowsize!(fig.layout, 2, Relative(0.5))
> trim!(fig.layout)
> CairoMakie.save("contour.png",fig)
> fig
> 
> ```

There are still a couple of things I’d like to improve.

- I’d like to write “WL” and “max” using an equivalent of \mathrm. Actually it looks it is not supported yet, but I maybe wrong (@sdanisch )
- I’d like the legend box to be perfectly aligned, while now is a bit higher than the [1,1] box
- I’d like to remove the white space between the subplots, as much as possible. In this situation it does not matter, but in general does kind of plots are 8x8 and removing the white space is crucial.

Overall, I am quite satisfied. `Makie` is quite beautiful!

---

<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:** [July 18, 2021, 4:58pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/8 "2021-07-18T16:58:18Z")

</div>

The reason why you have unnecessary whitespace is that you have set your axes to `aspect = 1`. The layout can’t optimize for multiple objects having their own aspect ratios, so what happens is that the axes get assigned one rectangular area each which is probably not square, but they adjust themselves to a square inside that rectangle. That leaves whitespace on the sides, and your legend at the top is aligned with the edge of that whitespace (which is of course not directly visible).

You can also think about it this way: If you specify the aspects of all axes in the Figure, it’s really unlikely that they fit into the given Figure size without whitespace, by chance. A workaround is to go the other way, specify the sizes of the axes (or other content), then adjust the Figure to the combined layout size. It’s currently not a documented approach but it works (with reaching into internals, though):

```julia
f = Figure(backgroundcolor = :gray90)
axs = [Axis(f[i, j], width = 200, height = 200)
    for i in 1:4, j in 1:2 if (i, j) != (1, 2)]

ls = map(axs) do ax
    lines!(ax, cumsum(randn(100)), color = rand(RGBf0))
end

hidexdecorations!.(axs[[1, 2, 3, 5, 6]])

Legend(f[1, 2], ls, string.(1:7), valign = :top, halign = :right, nbanks = 2)

# resize figure to the size reported by its top layout. this will only work
# if the layout size is determinable (known size elements in all rows / columns)
resize!(
    f.scene,
    f.layout.layoutobservables.reportedsize[]...
)

save("test.png", f)

```

 ![test](https://global.discourse-cdn.com/julialang/original/3X/3/c/3cb0a5cd22a6c4616a5597541a5befa49c05033b.png)

---

<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:** [July 18, 2021, 7:36pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/9 "2021-07-18T19:36:02Z")

</div>

Using `Plots` and `GR` you can more or less obtain what you wanted originally by using the `margin` attribute and creating an fake plot at the empty space:

```julia
empty = Plots.scatter(
  rand(1,3),rand(1,3),
  color=["red" "blue" "green"],
  ticks=:none,axis=false,
  label=["Series 1" "Series 2" "Series 3"],
  legendfont = (10, plot_font),
  markersize=0.5,
  marker=:square,
  markerstrokewidth=0,
  markeralpha=0.5,
  legend=:topleft
)

using Plots.Measures
p_contour = Plots.plot(
  pwa, 
  empty, 
  p_ell, 
  pw0, 
  layout = (2, 2), #link =:both,                              
  margin=0mm,
)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/c/2/c2340b02af8679508d262a677bdb187e25706a69.png)

> **full code**
>
> ```julia
> using Plots, LaTeXStrings
> 
> FisherMatrix = [16523.02 3319.2230;3319.2230 711.09] #Fisher matrix used in the MWE
> CovarianceMatrix = inv(FisherMatrix)
> σw0 = sqrt(CovarianceMatrix[1,1])
> σwa = sqrt(CovarianceMatrix[2,2])
> σw0wa = (CovarianceMatrix[1,2])
> plot_font = "Computer Modern"
> 
> Plots.default(
> titlefont = (16, plot_font), 
> fontfamily=plot_font, linewidth=1, 
> framestyle=:box, fg_legend =:black, 
> label=nothing, grid=false, tickfontsize=12, 
> size = (600, 500), labelfontsize = 15, dpi = 100,
> margin=-2mm
> )
> 
> #Needed for normalization
> function gaussian(μ::Float64, σ::Float64, x)
> return 1/(sqrt(2π*σ^2))*exp(-0.5*(x-μ)^2/σ^2)
> end
> 
> #Drawing ellipses
> t = LinRange(0,2π, 200)
> θ = 0.01*atan(2σw0wa/(σw0^2-σwa^2))/2#the 0.0
> a = (σw0^2+σwa^2)/2+sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
> b = (σw0^2+σwa^2)/2-sqrt(((σw0^2-σwa^2)^2)/4+σw0wa^2)
> x = a .* cos.(θ) .* cos.(t) - b .* sin.(θ) .* sin.(t)
> y = a .* sin.(θ) .* cos.(t) + b .* cos.(θ) .* sin.(t)
> p_ell = Plots.plot(x, y, linewidth = 1, legend = false, fill = (0, 0.5, :red),color="red")
> Plots.plot!(3x, 3y, linewidth = 1, legend = false, fill = (0, 0.5, :red), xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(-3b,stop=3b,length = 3),digits=4), xlim=(-4a,4a), ylim=(-4b,4b), color="red", ylabel = L"w_a", xlabel = L"w_0")
> 
> x = Array(LinRange(-4a,4a, 200))
> pwa = Plots.plot(x, gaussian.(0., a, x)./gaussian.(0., a, 0), fill=(0, .5,:red), legend = false, xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(0,stop=1,length=2),digits=2), color="red")
> x = Array(LinRange(-a,a, 200))
> Plots.plot!(pwa, x, gaussian.(0., a, x)./gaussian.(0., a, 0), fill=(0, .5,:red), legend = false, xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(0,stop=1,length=2),digits=2), color="red", ylabel = L"w_0")
> 
> x = Array(LinRange(-4b,4b, 200))
> pw0 = Plots.plot(x, gaussian.(0., b, x) ./gaussian.(0., b, 0.), fill=(0, .5,:red), legend = false, xticks = round.(range(-3b,stop=3b,length = 3),digits=4), yticks = round.(range(0,stop=1,length = 2)),figsize=(10,10), color="red")
> x = Array(LinRange(-b,b, 200))
> Plots.plot!(pw0, x, gaussian.(0., b, x) ./gaussian.(0., b, 0.), fill=(0, .5,:red), legend = false, xticks = round.(range(-3b,stop=3b,length = 3),digits=4), yticks = round.(range(0,stop=1,length = 2)),figsize=(10,10), color="red", xlabel = L"w_a", ymirror=true,)
> 
> empty = Plots.scatter(
> rand(1,3),rand(1,3),
> color=["red" "blue" "green"],
> ticks=:none,axis=false,
> label=["Series 1" "Series 2" "Series 3"],
> legendfont = (10, plot_font),
> markersize=0.5,
> marker=:square,
> markerstrokewidth=0,
> markeralpha=0.5,
> legend=:topleft
> )
> 
> using Plots.Measures
> p_contour = Plots.plot(pwa, empty, p_ell, pw0, layout = (2, 2), #link =:both, 
> margin=0mm,
> )
> 
> ```

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 19, 2021, 5:20am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/10 "2021-07-19T05:20:19Z")

</div>

[quote=“marcobonici, post:1, topic:64800”]

```julia
How to resolve that alert?

```

using LaTeXStrings

julia\> Plots.plot!(3x, 3y, linewidth = 1, legend = false, fill = (0, 0.5, :red), xticks = round.(range(-3a,stop=3a,length = 3),digits=2), yticks = round.(range(-3b,stop=3b,length = 3),digits=4), xlim=(-4a,4a), ylim=(-4b,4b), color=“red”, ylabel = L"w\_a", xlabel = L"w\_0")  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file  
latex: failed to create a dvi file

```julia

```

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 20, 2021, 1:02pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/11 "2021-07-20T13:02:20Z")

</div>

Thank you @jules ! Using your suggestions, the plot is quite nicer now.

 ![contour](https://global.discourse-cdn.com/julialang/original/3X/3/7/37b8f1972cd400782729c68fbea5f7fb2497f964.png)

The last issue is about the distance between the subplots. In this example (made with matplotlib) the distance between the subplots is constant

 ![Screenshot from 2021-07-20 14-15-50](https://global.discourse-cdn.com/julialang/original/3X/1/1/11a24ca13173f87ed895150f071d63b19462f551.png)

Is it possible to set the distance between the subplots in Makie? In particular, when I add P/P\_{max} on the y label, the distance between plots grows. If I understand correctly, Makie does so in order to avoid overlap between plots, am I right?

A possible workaround, is removing the ylabel, which is not necessary, obtaining the following result.

 ![contour](https://global.discourse-cdn.com/julialang/original/3X/a/2/a2fa0e43272f941bd23f0a8288ae5c5014482f9e.png)

Do you have any further suggestions?  
Thank you again,  
Marco

---

<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:** [July 20, 2021, 1:13pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/12 "2021-07-20T13:13:43Z")

</div>

In this case you have to tell Makie that you want the right protrusion of the upper-left axis to be 0, so that it doesn’t grow the column gap. This can be done with a different alignmode. Try setting `ax.alignmode = Mixed(right = MakieLayout.Protrusion(0))` for the upper-left axis.

```julia
f = Figure(resolution = (600, 600))

ax = Axis(f[1, 1], ylabel = "a label", yaxisposition = :right,
    alignmode = Mixed(right = MakieLayout.Protrusion(0))
)
Axis(f[2, 1])
Axis(f[2, 2])

f

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/a/5/a511b7981d77e20e28431785eeefec090c634877.png)

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 20, 2021, 4:59pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/13 "2021-07-20T16:59:19Z")

</div>

Thank you!  
Using protrusion, I obtained the following.

 ![contour](https://global.discourse-cdn.com/julialang/original/3X/f/5/f53221af33833fa548510f31722051e288b160e5.png)

About the y label, it’s exactly what I wanted.  
The last point (and then I am done) regards the shapes of the subplots. Manually setting the (overall) plot size I can fix it. Is there a way to use both protrusin and fix the subplots size?

Thank you again,  
Marco

---

<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:** [July 20, 2021, 6:14pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/14 "2021-07-20T18:14:16Z")

</div>

What exactly is your goal regarding the figure or subplot size? Looks good to me

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 20, 2021, 8:21pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/15 "2021-07-20T20:21:13Z")

</div>

Indeed, this is true! This plot looks good!  
However, I had to set manually the size of the figure to obtain (almost) squared subplots. In general, I make plots with higher number of rows and columns (from 5 to 8) and, if possible, I would prefer not to set manually the plot size to obtain squared subplots. However, if this is not possible, the result obtained is very good and requires only a bit of manual work.

---

<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:** [July 20, 2021, 8:38pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/16 "2021-07-20T20:38:04Z")

</div>

So the way I showed above where you set the subplot size, and then the figure size is derived from that, doesn’t work for you? That sounds like what you want to me.

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 20, 2021, 10:56pm UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/17 "2021-07-20T22:56:22Z")

</div>

Yeah, but I am not being able to combine the two methods together.  
I obtain the following error

```julia
type Mixed has no field padding

```

> **Code**
>
> ```julia
> f = Figure(backgroundcolor = :gray90)
> axs = [Axis(f[i, j], width = 200, height = 200, alignmode = Mixed(right = MakieLayout.Protrusion(0)))
> for i in 1:4, j in 1:2 if (i, j) != (1, 2)]
> 
> ls = map(axs) do ax
> lines!(ax, cumsum(randn(100)), color = rand(RGBf0))
> end
> 
> hidexdecorations!.(axs[[1, 2, 3, 5, 6]])
> 
> Legend(f[1, 2], ls, string.(1:7), valign = :top, halign = :right, nbanks = 2)
> 
> # resize figure to the size reported by its top layout. this will only work
> # if the layout size is determinable (known size elements in all rows / columns)
> resize!(
> f.scene,
> f.layout.layoutobservables.reportedsize[]...
> )
> 
> f
> 
> ```

Am I doing something bad?

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [July 21, 2021, 1:14am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/18 "2021-07-21T01:14:32Z")

</div>

Hi @marcobonici When you are done, can you post your full codes here? I found it very useful. Thanks!

---

<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:** [July 21, 2021, 8:40am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/19 "2021-07-21T08:40:42Z")

</div>

Oh that is a bug, I’ll have a look tonight.

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [July 21, 2021, 10:01am UTC](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800/20 "2021-07-21T10:01:25Z")

</div>

Thank you, I really appreciate that:)

[Next page](https://discourse.julialang.org/t/multiple-plots-some-refinements/64800.md?page=2)
