首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置从数据框中绘制的表格的格式

设置从数据框中绘制的表格的格式
EN

Stack Overflow用户
提问于 2021-01-13 04:33:17
回答 1查看 29关注 0票数 0

我正在尝试发布从数据帧创建的表的图形,以便在报告中使用。

代码语言:javascript
复制
#Hard Coding example
TopTenSites = 238
RestOfSites = 387
#Creating a dataframe to pass into 
Proportion = pd.DataFrame({'Incidence': [TopTenSites, RestOfSites]},
             index=['Top 10 Sites', 'Rest of Sites'])

#Creating the table
fig, plot = plt.subplots(figsize = [3,2])
#plot.axis('off')
#Remove axis
plot.xaxis.set_visible(False) 
plot.yaxis.set_visible(False) 
#Creating the table
plot.table(cellText = Proportion.values, rowLabels = Proportion.index, loc = 'center', colLabels = 
Proportion.columns,cellLoc = 'center')
plt.savefig('Proportion.png')enter code here

Jupyter notebook中的输出给出了一个如下所示的表格。

但此代码实际生成的png如下所示

有没有人知道表格的格式,这样我就可以生成一个png文件,它看起来与包含行标签的输出完全一样。

EN

回答 1

Stack Overflow用户

发布于 2021-01-13 05:29:44

答案是使用默认的数字索引重新创建数据帧

代码语言:javascript
复制
#Creating a dataframe to pass into 
Proportion = pd.DataFrame({'Sites': ['Top 10 Sites', 'Rest of Sites'],'Incidence': 
[TopTenSites, RestOfSites]})

#Creating the table plot
fig, plot = plt.subplots(figsize = [3,2])
plot.axis('off')
#Remove axis
plot.xaxis.set_visible(False) 
plot.yaxis.set_visible(False) 
#Creating the table
plot.table(cellText = Proportion.values,loc = 'center', colLabels = 
Proportion.columns, cellLoc = 'center')
plt.savefig('Proportion.png')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65691654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档