简体   繁体   English

plot 的附加标题

[英]Addition title to plot

How can I add titles to each subplot here?如何在此处为每个子图添加标题?

 fig, axs = plt.subplots(ncols=4, nrows=2, figsize=(16,8))
 for city, nrow in zip(['City1', 'City1'], [0, 1]):
    df = data[(data.city==city)&(data.sdate.dt.year==2021)]
    for col, ncol in zip(['parameterX', 'parameterY', 'parameterZ', 'parameterH'], [0,1, 2,3]):
    axs[nrow, ncol].hist(df[col], bins=50)

在此处输入图像描述

just do at the end最后做

fig, axs = plt.subplots(ncols=4, nrows=2, figsize=(16,8))
 for city, nrow in zip(['City1', 'City1'], [0, 1]):
    df = data[(data.city==city)&(data.sdate.dt.year==2021)]
    for col, ncol in zip(['parameterX', 'parameterY', 'parameterZ', 'parameterH'], [0,1, 2,3]):
        axs[nrow, ncol].hist(df[col], bins=50)
        axs[nrow, ncol].set_title('my_subplot_title') 

Customize the title with column, row name and add it as below.使用列、行名称自定义标题并将其添加如下。

fig, axs = plt.subplots(ncols=4, nrows=2, figsize=(16,8))
for city, nrow in zip(['City1', 'City1'], [0, 1]):
    df = data[(data.city==city)&(data.sdate.dt.year==2021)]
    for col, ncol in zip(['parameterX', 'parameterY', 'parameterZ', 'parameterH'], [0,1, 2,3]):
        axs[nrow, ncol].hist(df[col], bins=50)
        title=city+'_'+col
        axs[nrow, ncol].set_title(title)
        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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