How to keep all the subplots have the same Y axis range in julia?

144 views Asked by At

I want a grouped plot that shows the distributions of events according to the hour (0 - 23 hour). I did not find an elegant way to do it, so I just used the most inefficient way to plot it. Now it looks like this.

enter image description here

For each of the subplots, the y axis is log10 scaled. I want to make changes to the plot:

  1. make all the y axis have the same range (I tried several methods, but did not get them through);
  2. add the label to the x and y axis. (I added them, but it assigned each of the subplots the same x and y label);
  3. add the title for the grouped plot (I used title = "Test", and it assigned the title to all the subplots).
p0 = StatsPlots.histogram((d1_0_degree), bins=50, yscale=:log10, label = "0", color = ColorSchemes.Set3_12.colors[1])
p1 = StatsPlots.histogram((d1_1_degree), bins=50, yscale=:log10, label = "1", color = ColorSchemes.Set3_12.colors[2]);
p2 = StatsPlots.histogram((d1_2_degree), bins=50, yscale=:log10, label = "2", color = ColorSchemes.Set3_12.colors[3]);
p3 = StatsPlots.histogram((d1_3_degree), bins=50, yscale=:log10, label = "3", color = ColorSchemes.Set3_12.colors[4]);
p4 = StatsPlots.histogram((d1_4_degree), bins=50, yscale=:log10, label = "4", color = ColorSchemes.Set3_12.colors[5]);
p5 = StatsPlots.histogram((d1_5_degree), bins=50, yscale=:log10, label = "5", color = ColorSchemes.Set3_12.colors[6]);
p6 = StatsPlots.histogram((d1_6_degree), bins=50, yscale=:log10, label = "6", color = ColorSchemes.Set3_12.colors[7]);
p7 = StatsPlots.histogram((d1_7_degree), bins=50, yscale=:log10, label = "7", color = ColorSchemes.Set3_12.colors[8]);
p8 = StatsPlots.histogram((d1_8_degree), bins=50, yscale=:log10, label = "8", color = ColorSchemes.Set3_12.colors[9]);
p9 = StatsPlots.histogram((d1_9_degree), bins=50, yscale=:log10, label = "9", color = ColorSchemes.Set3_12.colors[10]);
p10 = StatsPlots.histogram((d1_10_degree), bins=50, yscale=:log10, label = "10", color = ColorSchemes.Set3_12.colors[11]);
p11 = StatsPlots.histogram((d1_11_degree), bins=50, yscale=:log10, label = "11", color = ColorSchemes.Set3_12.colors[12]);
p12 = StatsPlots.histogram((d1_12_degree),  bins=50, label = "12", yscale=:log10, color = ColorSchemes.Paired_12.colors[1]);
p13 = StatsPlots.histogram((d1_13_degree),  bins=50, label = "13", yscale=:log10, color = ColorSchemes.Paired_12.colors[2]);
p14 = StatsPlots.histogram((d1_14_degree),  bins=50, label = "14", yscale=:log10, color = ColorSchemes.Paired_12.colors[3]);
p15 = StatsPlots.histogram((d1_15_degree),  bins=50, label = "15", yscale=:log10, color = ColorSchemes.Paired_12.colors[4]);
p16 = StatsPlots.histogram((d1_16_degree),  bins=50, label = "16", yscale=:log10, color = ColorSchemes.Paired_12.colors[5]);
p17 = StatsPlots.histogram((d1_17_degree),  bins=50, label = "17", yscale=:log10, color = ColorSchemes.Paired_12.colors[6]);
p18 = StatsPlots.histogram((d1_18_degree),  bins=50, label = "18", yscale=:log10, color = ColorSchemes.Paired_12.colors[7]);
p19 = StatsPlots.histogram((d1_19_degree),  bins=50, label = "19", yscale=:log10, color = ColorSchemes.Paired_12.colors[8]);
p20 = StatsPlots.histogram((d1_20_degree),  bins=50, label = "20", yscale=:log10, color = ColorSchemes.Paired_12.colors[9]);
p21 = StatsPlots.histogram((d1_21_degree),  bins=50, label = "21", yscale=:log10, color = ColorSchemes.Paired_12.colors[10]);
p22 = StatsPlots.histogram((d1_22_degree),  bins=50, label = "22", yscale=:log10, color = ColorSchemes.Paired_12.colors[11]);
p23 = StatsPlots.histogram((d1_23_degree),  bins=50, label = "23", yscale=:log10, color = ColorSchemes.Paired_12.colors[12]);

p_degreelog = Plots.plot(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, 
frame=:box, 
layout = (4,6), legend = true, size=(1400, 600), link=(:x) )

1

There are 1 answers

0
max xilian On

You can generate those plots in a for loop as well. Take a look:

using Plots 

hists = []
ylimits = [0,30]
for i=1:10
    push!(hists, histogram(rand(100), ylims=ylimits, xlabel="Test x"))
end

plot(hists..., plot_title="TITLE")

See the ylims for setting the limits, xlabel for the axis label, and plot_title for setting the title.