I have a Pandas dataframe, and i want to plot it as matplotlib table. So far i have that part working with following code:
import numpy as np
randn = np.rand
The Andy's code working:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sudo apt-get install python-pandas
# sudo apt-get install python-matplotlib
#
# python teste.py
from matplotlib import pyplot
from matplotlib import cm
import numpy
from pandas import *
idx = Index(numpy.arange(1, 11))
df = DataFrame(
numpy.random.randn(10, 5),
index=idx,
columns=['A', 'B', 'C', 'D', 'E']
)
vals = numpy.around(df.values, 2)
normal = pyplot.normalize(vals.min()-1, vals.max()+1)
fig = pyplot.figure(figsize=(15, 8))
ax = fig.add_subplot(111, frameon=True, xticks=[], yticks=[])
the_table = pyplot.table(
cellText=vals,
rowLabels=df.index,
colLabels=df.columns,
colWidths = [0.03]*vals.shape[1],
loc='center',
cellColours=pyplot.cm.hot(normal(vals))
)
pyplot.show()