Python 选择matplotlib中要打印的子批次

Python 选择matplotlib中要打印的子批次,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在编写一个函数来显示给定数据帧中每列的前10个值的摘要 假设我们有以下数据帧: df = pd.DataFrame({'a':[1, 2, 3, 1, 2, 3, 1, 4, 4, 5, 6], 'b':[2, 1, 1, 1, 1, 1, 1, 4, 4, 5, 6], 'c':[1, 2, 3, 1, 2, 5, 5, 5, 5, 5, 6]}) 我希望能够计算列数,并创建一个大小相同的绘图网格 我已经使用元组

我正在编写一个函数来显示给定数据帧中每列的前10个值的摘要

假设我们有以下数据帧:

df = pd.DataFrame({'a':[1, 2, 3, 1, 2, 3, 1, 4, 4, 5, 6],
                   'b':[2, 1, 1, 1, 1, 1, 1, 4, 4, 5, 6],
                   'c':[1, 2, 3, 1, 2, 5, 5, 5, 5, 5, 6]})
我希望能够计算列数,并创建一个大小相同的绘图网格

我已经使用元组创建并找到了正确的方形网格选择:

l = len(df.columns)
tups = [(z, z, z**2) for z in range(1, 10)]
param = tups[min([i for i, x in enumerate([l <= tup[2] for tup in tups]) if x])]
我遇到的困难是,我想为每个子图绘制每个网格,但当我迭代时,它只会将每个网格设置为最后一个网格图,而将其他网格图留空

for col in df.columns:
    df[col].value_counts()[:10].plot('bar')

这肯定已经在其他地方得到了回答,但由于种种原因,我可能会在这里再次键入

for i, col in enumerate(df.columns):
    ax = plt.subplot(param[0],param[1],i+1)
    df[col].value_counts()[:10].plot('bar', ax=ax)
for i, col in enumerate(df.columns):
    ax = plt.subplot(param[0],param[1],i+1)
    df[col].value_counts()[:10].plot('bar', ax=ax)