【发布时间】:2018-01-02 17:37:20
【问题描述】:
我正在尝试从数据框中获取输出,该数据框显示堆叠的水平条形图,其左侧有一个表格。相关数据如下:
import pandas as pd
import matplotlib.pyplot as plt
cols = ['metric','target','daily_avg','days_green','days_yellow','days_red']
vals = ['Volume',338.65,106.81,63,2,1]
OutDict = dict(zip(cols,vals))
df = pd.DataFrame(columns = cols)
df = df.append(OutDict, ignore_index = True)
我想获得类似于以下内容的内容:Python Matplotlib how to get table only。我可以得到堆积条形图:
df[['days_green','days_yellow','days_red']].plot.barh(stacked=True)
添加关键字参数table=True 在图表下方放置一个表格。如何让轴将 df 显示为表格或在图表旁边添加一个。此外,DataFrame 最终将有不止一行,但如果我能让它为一行工作,那么我应该能够让它为 n 行工作。
提前致谢。
【问题讨论】:
标签: python python-3.x pandas matplotlib