【发布时间】:2021-07-08 05:04:59
【问题描述】:
我正在使用 pycharm 使用 matplotlib 库输出此表。但是我想根据值为单元格着色。
我目前的代码是
import matplotlib.pyplot as plt
import pandas as pd
fig, ax =plt.subplots(1,1)
ax.axis('tight')
ax.axis('off')
table_data = pd.read_csv("test.csv")
table_data =table_data.astype({"Runs":int, "HS":int})
table_data =table_data.sort_values(by='HS')
df = table_data
table = ax.table(cellText=df.values,
colLabels=df.columns,
loc="center",
cellLoc="left")
table.auto_set_column_width(col=list(range(len(df.columns))))
plt.show()
我的数据集的“HS”列和“S/R”列的输出应类似于“BasePay”列和“OtherPay”列(请参阅下图)。
我尝试在 python 上使用样式库,但它们不会在 pycharm 上本地打印,因此我需要它作为 plt.show()
【问题讨论】:
标签: python pandas matplotlib visualization