简体   繁体   中英

Subplot with multiple subplots

I am drawing 4 sets of 12 plots (ie 48 plots in total). I want to combine the 12 plots within each of the 4 sets into one figure. However, I do not know how to combine the plots. At the moment, I am only drawing the 48 plots.

The dictionary I am referring to in the following contains 4 dictionaries, in turn containing 12 datasets each:

import matplotlib.pyplot as plt
import seaborn as sns

for j in dic:
    for i in dic[j]:
        df = pd.concat(dic[j][i].values(), ignore_index=True)
        var = np.random.normal(loc=0, scale=1, size=10000)
        fig, ax = plt.subplots()
        sns.histplot(df['Z'], stat='density', ax=ax)
        sns.kdeplot(var, color='r', ax=ax)

Thanks to @GenG, I found the solution:

temp_1 = [0,1,2,0,1,2,0,1,2,0,1,2]
temp_2 = [0,0,0,1,1,1,2,2,2,3,3,3]

for j in dic:
    fig, ax = plt.subplots(3,4)
    for i, t, k in zip(dic[j], temp_1, temp_2):
        df = pd.concat(dic[j][i].values(), ignore_index=True)
        var = np.random.normal(loc=0, scale=1, size=10000)
        sns.histplot(df['Z'], stat='density', ax=ax[t][k])
        sns.kdeplot(var, color='r', ax=ax[t][k])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM