【发布时间】:2020-06-25 00:42:52
【问题描述】:
下面是数据库,然后编码然后输出,它有标题(价格)和子标题(CPU,维护和软件)
Rep Manager Product Quantity Price Status
Craig Booker Debra Henley CPU 1 30000.125 Presented
Craig Booker Debra Henley Software 1 10000.340 Presented
Craig Booker Debra Henley Maintenance 2 5000.359 Pending
Craig Booker Debra Henley CPU 1 35000.679 Declined
Daniel Hilton Debra Henley CPU 2 65000.000 Won
Cedric Moss Fred Anderson Software 3 27500.000 Presented
Wendy Yule Fred Anderson Maintenance 4 44250.000 Won
import pandas as pd
from pandas.plotting import table
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_excel('Book1.xlsx')
df
df=df.pivot_table(df,index=['Manager','Status'],columns=['Product'],aggfunc={'Price':np.sum,'Quantity':len},fill_value='-',margins=False)
df
但是当我在一个带有下面编码标题和子标题的图中绘制时,它们被合并到一个单元格中。请问如何避免这种情况?
fig=plt.figure(figsize=(15,10))
ax=plt.subplot(111,frame_on=False)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
tb1=table(ax,df,loc='center',colWidths=[0.15, 0.24, 0.2,0.2,0.25,0.22])
tb1.set_fontsize(17)
tb1.scale(1,7)
plt.show()
*我希望价格和数量位于顶部,带有子标题(CPU、维护和软件),如第一张图片所示。
谢谢*
【问题讨论】:
标签: python-3.x pandas matplotlib