用python的画表格

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
randn = np.random.randn
from pandas import *
idx = Index(np.arange(1,7))
df = DataFrame(randn(6, 4), index=idx, columns=['A', 'B', 'C', 'D'])
vals = np.around(df.values,2)
fig = plt.figure(figsize=(9,4))
ax = fig.add_subplot(111, frameon=True, xticks=[], yticks=[])
the_table=plt.table(cellText=vals, rowLabels=df.index, colLabels=df.columns, 
                    colWidths = [0.1]*vals.shape[1], loc='center',cellLoc='center')
the_table.set_fontsize(20)

the_table.scale(2.5,2.58)

使用matplot表值画图的图例调整为表格

用python的画表格_第1张图片

 

缺点是:不能像数据框一样对齐

你可能感兴趣的:(python)