Plot size from subplots sizes

Hello

I am creating multiple plots in this generic way:

plot(p1,p2,p3, layout=grid(1,3, widths=(4/9,4/9,1/9)), size=(900,350))

My problem is that all of the plots p1,p2,p3 have already been given good sizes.
When plotted each individually, they appear exactly as I wishes.

However, when plotted together with some layout and global size, they are not exactly plotted as before.
For example, the multiline titles overfill the plot frame below, the sizes are not exactly as I wish, even the aspect ratio is different.

Is it possible to arrange a multiple plot is such a way that it juxtaposes the subplots with the size, aspect ratio and everyting as originally defined? And sizing the plot and the heights and the widths as needed. The layout and the size should then be automatically adjusted to render the subplots as by their original definitions.

As an alternative, I imagined saving the original subplots in jpeg files and then displaying them in a multiple plot. But even so, I expect some troubles with the sizes. But it might help a little bit.

How do manage such things?

Thanks for your suggestions,

Michel

A MWE please.

Thanks rafael.

Below is a MWE.

The function returns a typical plot.
The first test shows this typical plot.
The second test shows the same plot twice as subplots.

As you can see the output in the second plot has been somewhat distorded.
The two-lines title now overlaps inside the plot frame.
The x-guide and y-guide texts are not totally visible.

If I look at the svg files I can see the expected size in pixels (400x300 and 800x300).
This is also a bit puzzling since I cannot see then any reason for the distortion.

I have tried changing sizes and other possible tricks, but no solution.

My aim is simply to show two such plots side-by-side shown exactly in the same way as when I plot them alone.
I have no explanation for this behaviour, this is a bit mysterious.
Could it be related to pixels and fonts? Or anything else?

Thanks for your suggestions

Michel


This is a function that returns a typical plot:

using Plots

function testplot()
    Di = 1:9
    Ei = [215, 125, 89, 69, 56, 47, 41, 36, 32]
    Oi = [216, 163, 88, 74, 61, 40, 25, 26, 22]
    markColor = [:green,:red,:green,:green,:green,:green,:red,:red,:red]
    title = "This is a test\n N=175, chi²=26  ** Poor fit"
    p = plot(xtickfontsize=8,ytickfontsize=8,xguidefontsize=8,yguidefontsize=8, titlefont=font(10))
    plot!(size=(400,300), background_color="ivory", framestyle = :box)
    plot!(title=title, xlabel="digit", ylabel="count")
    plot!(xticks=Di, ylim=(0,Inf))
    plot!(Di, Ei, ribbon=1*sqrt.(Ei), label="1σ CI", fillcolor="gray65")
    plot!(Di, Ei, ribbon=2*sqrt.(Ei), label="2σ CI", fillcolor="gray85")
    scatter!(Di, Oi, label="data", markercolor=markColor)
end

This is a first test:

p = testplot()

and its output I get in Jupyterlab:
p


This is second test:
(observe the distortion)

p = testplot()
plot(p,p, layout=grid(1,2, widths=(4/8,4/8)), size=(800,300))

and its output:

One way to fix this type of issue is using Measures and plot() keyword margin, which can be tuned with left, top, … prefixes, for each individual plot or for all.

using Measures
p = testplot()
plot(p,p, layout=grid(1,2, widths=(4/8,4/8)), size=(800,300), margin=5mm)

Thanks a lot, Rafael.

1 Like