【发布时间】:2020-03-13 02:57:45
【问题描述】:
我有以下数据框。
df = '''type time gender
0 A 660.0 M
1 B 445.0 M
2 C 68.0 M
3 A 192.2 F
4 B 82.9 F
'''
我在数据上方使用下面的代码图。
import matplotlib.ticker as mtick
import matplotlib.pyplot as plt
df.groupby(['gender','type']).count().groupby(level=0).apply(
lambda x:100*x / x.sum()
).unstack().plot(kind='bar',stacked=True)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter())
plt.legend( prop={'size': 16})
plt.show()
我的输出:
问:我想用涉及数据时间的方式绘制这两个条形图。 如果有人可以提供帮助,请不胜感激!
【问题讨论】:
-
involving the time of the data是什么意思?您想要y轴上的实际时间吗? -
是的。我想用实际时间绘制条形
标签: python pandas charts bar-chart