我正在尝试使用交叉表函数从数据框中的2列绘制饼形图,到目前为止,我可以使用下面的语句绘制条形图。
数据帧示例:

pd.crosstab(df['event_location'],df['event_type']).iplot(kind="bar", bins=20, theme="white", title="Event type over Location",xTitle='location', yTitle='Number of person')

我的问题是如何将这个条形图转换成饼图?
发布于 2020-10-08 20:04:22
我猜您正在尝试显示每种事件类型的发生次数。这段简单的代码将帮助您绘制每个位置的饼图。
import matplotlib.pyplot as plt
ct = pd.crosstab(df['event_location'],df['event_type'])
ct.plot.pie(subplots=True)
plt.legend(title='XYZ')
plt.show()https://stackoverflow.com/questions/64261573
复制相似问题