Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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函数将所有直方图绘制到同一个绘图中,而不是为每个迭代创建不同的绘图_Python_Matplotlib_Seaborn - Fatal编程技术网

Python函数将所有直方图绘制到同一个绘图中,而不是为每个迭代创建不同的绘图

Python函数将所有直方图绘制到同一个绘图中,而不是为每个迭代创建不同的绘图,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,您缺少的是distplot内部的参数ax。 首先,您不需要网格6x6,因为您有一个由4个元素组成的列表。 您可以按如下方式修改代码: list1 = ['PG','UN','HH-RF','MKT-RF'] f, axes = plt.subplots(6, 6, figsize=(20, 20), sharex=True) for i in (list1): sns.distplot(df[i], kde=False, bins=40) 通过这种方式,您可以将每个df绘制到子批次的特

您缺少的是distplot内部的参数
ax
。 首先,您不需要网格
6x6
,因为您有一个由4个元素组成的列表。 您可以按如下方式修改代码:

list1 = ['PG','UN','HH-RF','MKT-RF']
f, axes = plt.subplots(6, 6, figsize=(20, 20), sharex=True)
for i in (list1):
    sns.distplot(df[i], kde=False, bins=40)

通过这种方式,您可以将每个
df
绘制到子批次的特定框中。

我尝试过实现它,但现在x轴上的标签消失了,尽管我看到了不同的绘图。我认为
ax\u list[index].xlabel(I)
不起作用。您需要
ax\u列表[index]。设置标签(i)
list1 = ['PG','UN','HH-RF','MKT-RF']
f, axes = plt.subplots(2, 2, figsize=(20, 20), sharex=True)
ax_list = axes.flatten()
for index, i in enumerate(list1):
    sns.distplot(df[i], kde=False, bins=40, ax=ax_list[index])
    # Showing the x label
    ax_list[index].set_xlabel(i)