Matplotlib表绘制布局控件

时间:2016-03-03 17:32:46

标签: python pandas matplotlib plot

我总是在将表放入Matplotlib图中时遇到问题。这是one example。即,表格和我的图表总是相互重叠:

table and graph are overlapping

现在我在想,如何在不同的子图中分离它们?所以我试了一下,same example,第二张图。它看起来很糟糕:

separating them in different subplots

问题是我不知道为什么我的简单改变会产生如此巨大的差异。有人可以帮我修理吗?

重新发布脚本:

# On Same graph

plt.close('all')  # close all open figures

fig, ax = plt.subplots()

# X: pd.options.display.mpl_style = 'default' # cause system freeze
df.set_index(['person']).plot(kind='barh', ax = ax, width=0.85, fontsize=8)
ax.invert_yaxis()

plt.title("Matplotlib table plotting")

#plt.tight_layout()

# Add a table
plt.table(cellText=df.values,colWidths = [0.25]*len(df.columns),
        rowLabels=df.index,
        colLabels=df.columns,
        cellLoc = 'center', rowLoc = 'center',
        loc='top')

# separate them in different subplots

plt.close('all')  # close all open figures

fig, ax = plt.subplots(2,1)

# Add a table first
ax[0].table(cellText=df.values,colWidths = [0.25]*len(df.columns),
        rowLabels=df.index,
        colLabels=df.columns,
        cellLoc = 'center', rowLoc = 'center',
        loc='top')

# keep the y tick labels from getting too crowded
#plt.subplots_adjust(hspace = 3.6)

# X: pd.options.display.mpl_style = 'default' # cause system freeze
df.set_index(['person']).plot(kind='barh', ax = ax[1], width=0.85, fontsize=8)
ax[1].invert_yaxis()

plt.title("Matplotlib table plotting")

由于

0 个答案:

没有答案