Python 3.x matplotlib在dataframe中自定义打印多列

Python 3.x matplotlib在dataframe中自定义打印多列,python-3.x,pandas,matplotlib,Python 3.x,Pandas,Matplotlib,我有一个pandasDataFrame,有多个列,我想为每个列绘制直方图,我想有一个单独的直方图,并在绘制完成后将所有直方图放在一行中 以下是我的尝试: fig, ax = plt.subplots(nrows=1, ncols=4, figsize=(20,5)) n_cols = ['a', 'b', 'c', 'd'] colors = ['#800000','#3C91E6','#59C9A5','#9BE564'] counter = 0 for j in range(4):

我有一个
pandas
DataFrame
,有多个列,我想为每个列绘制
直方图
,我想有一个单独的直方图,并在绘制完成后将所有直方图放在一行中

以下是我的尝试:

fig, ax = plt.subplots(nrows=1, ncols=4, figsize=(20,5))

n_cols = ['a', 'b', 'c', 'd']
colors = ['#800000','#3C91E6','#59C9A5','#9BE564']
counter = 0

for j in range(4):
    n, bins, patches = plt.hist(df[n_cols[counter]], 
                                bins=50, 
                                facecolor = '#2ab0ff', 
                                edgecolor='#169acf', 
                                linewidth=0.5, ax=ax[j])
    n = n.astype('int') # it MUST be integer#
    for i in range(len(patches)):
        patches[i].set_facecolor(plt.cm.viridis(n[i]/max(n)))
    # Make one bin stand out   
    patches[47].set_fc('red') # Set color
    patches[47].set_alpha(1) # Set opacity        
    counter+=1

    fig.suptitle('distributions', fontsize=18)
我得到一个
inner()为参数ax得到了多个值

但一个单一的情节运作良好,没有任何问题。哪一个是循环中的部分:

Matplotlib没有像pandas/seaborn那样使用
ax
param。Matplotlib使用
ax[j].plot()
而不是
plt.plot(ax=ax[j])

n,bin,patches=ax[j].hist(df[n_cols[counter]],
垃圾箱=50,
facecolor='#2ab0ff',
edgecolor=“#169acf”,
线宽=0.5)

还有一个很好的问题,获取每个绘图轴名称和标题的最佳方法是什么?
ax[j]。title(“title”)
但是text object not callableget not
ax[j]。title
its
set\u title