Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将唯一标题添加到matplotlib中for循环内的子批次_Python_Pandas_For Loop_Matplotlib_Subplot - Fatal编程技术网

Python 将唯一标题添加到matplotlib中for循环内的子批次

Python 将唯一标题添加到matplotlib中for循环内的子批次,python,pandas,for-loop,matplotlib,subplot,Python,Pandas,For Loop,Matplotlib,Subplot,我已经检查了其他答案,所以这似乎没有帮助我解决这个问题。我已经从pandasdf中的列创建了子图。我希望每个子批次在每个标题末尾都有一个唯一的日期,这是我在循环中尝试的。发生的情况是,标题只出现在最后一个图形上,而没有其他图形。为什么会这样 area2011 = df_2011.groupby(['Area Id']).size() area2012 = df_2012.groupby(['Area Id']).size() area2013 = df_2013.groupby(['Area I

我已经检查了其他答案,所以这似乎没有帮助我解决这个问题。我已经从
pandas
df
中的列创建了子图。我希望每个
子批次
在每个标题末尾都有一个唯一的日期,这是我在循环中尝试的。发生的情况是,标题只出现在最后一个图形上,而没有其他图形。为什么会这样

area2011 = df_2011.groupby(['Area Id']).size()
area2012 = df_2012.groupby(['Area Id']).size()
area2013 = df_2013.groupby(['Area Id']).size()
area2014 = df_2014.groupby(['Area Id']).size()
area2015 = df_2015.groupby(['Area Id']).size()
area2016 = df_2016.groupby(['Area Id']).size()
area_list = [area2011, area2012, area2013, area2014, area2015, area2016]
fig, axes = plt.subplots(2, 3)
for i in range(2011, 2017):
    for d, ax in zip(area_list, axes.ravel()):
        plt.title(f'Area Id crimes in {i}')
        d.plot.bar(ax=ax, figsize=(15, 7))
        plt.tight_layout()
从第一个到最后一个
子批次
我想生产:

"Area Id crimes in 2011"
   .
   .
   .
"Area Id crimes in 2016"

我认为发布答案会更快。下面是:

for i in range(2011, 2017):
    for d, ax in zip(area_list, axes.ravel()):
        plt.title(f'Area Id crimes in {i}')
        d.plot.bar(ax=ax, figsize=(15, 7))
        plt.tight_layout()
最后一次运行(
i=2016
)时,外部
for
循环将所有内容设置为
f'Area Id crimes in{i}
,即
'Area Id crimes in 2016'

for d, i in zip(area_list, range(6)):
    ax = axes.ravel()[i];
    ax.set_title(f'Area Id crimes in {i+2011}')
    d.plot.bar(ax=ax, figsize=(15, 7))
    plt.tight_layout()

我认为发布答案会更快。下面是:

for i in range(2011, 2017):
    for d, ax in zip(area_list, axes.ravel()):
        plt.title(f'Area Id crimes in {i}')
        d.plot.bar(ax=ax, figsize=(15, 7))
        plt.tight_layout()
最后一次运行(
i=2016
)时,外部
for
循环将所有内容设置为
f'Area Id crimes in{i}
,即
'Area Id crimes in 2016'

for d, i in zip(area_list, range(6)):
    ax = axes.ravel()[i];
    ax.set_title(f'Area Id crimes in {i+2011}')
    d.plot.bar(ax=ax, figsize=(15, 7))
    plt.tight_layout()

ax.set_title()
?尝试
ax.title.set_text(f'Area Id crimes in{i}')
@QuangHoang这两种解决方案只需在所有子地块上打印“Area Id crimes in 2016”。它不会在循环中循环range@MohamedThasinahWhy双
for
循环:
for i in range(2011,2017):for d,ax in zip(area_list,axes.ravel()):
ax.set_title()
?try
ax.title.set_text(f'area Id crimes in{i}')
@QuangHoang两种解决方案只需在所有子批次上打印“area Id crimes in 2016”。它不会在循环中循环range@MohamedThasinahWhy双
for
循环:
for i in range(2011、2017):for d,ax in zip(area_list,axes.ravel()):