Tôi có một khung dữ liệu Pandas và tôi muốn vẽ nó thành bảng matplotlib. Cho đến nay tôi đã phần đó làm việc với mã sau:matplotlib: sử dụng bản đồ màu để tô màu nền bảng
import numpy as np
randn = np.random.randn
from pandas import *
idx = Index(arange(1,11))
df = DataFrame(randn(10, 5), index=idx, columns=['A', 'B', 'C', 'D', 'E'])
vals = np.around(df.values,2)
fig = plt.figure(figsize=(15,8))
ax = fig.add_subplot(111, frameon=True, xticks=[], yticks=[])
the_table=plt.table(cellText=vals, rowLabels=df.index, colLabels=df.columns,
colWidths = [0.03]*vals.shape[1], loc='center')
table_props = the_table.properties()
table_cells = table_props['child_artists']
clm = cm.hot(vals)
for cell in table_cells:
cell.set_height(0.04)
# now i would like to set the backgroundcolor of the cell
Vào cuối này tôi muốn thiết lập background-color của tế bào theo colormap - nhưng làm thế nào để tôi nhìn nó lên trong CLM mảng không có chỉ mục?
Một câu hỏi khác: tôi có thể bằng cách nào đó chuyển chuỗi định dạng vào bảng để định dạng văn bản thành 2 chữ số thập phân không?
Bất kỳ gợi ý đánh giá cao, Andy