好的,我做了一些研究,这几乎涵盖了我想做的事情.使用matplotlib colormaps做了伎俩.这里是地图颜色选项的链接.
matplotlib color maps
我带着RdYlGn着色.
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
df = pd.DataFrame(np.random.randn(10, 8), columns=list('abcdefgh'))
print df
#Round to two digits to print nicely
vals = np.around(df.values, 2)
#Normalize data to [0, 1] range for color mapping below
normal = (df - df.min()) / (df.max() - df.min())
fig = plt.figure()
ax = fig.add_subplot(111)
ax.axis('off')
the_table=ax.table(cellText=vals, rowLabels=df.index, colLabels=df.columns,
loc='center', cellColours=plt.cm.RdYlGn(normal),animated=True)
fig.savefig("table.png")
输出: