【发布时间】:2020-08-23 10:51:32
【问题描述】:
我的 groupby 挑战我正在尝试使用折线图可视化 10 年来非洲国家(我的数据中的 45 个)的粮食生产。使用 groupby 函数和 unstack 后,绘图效果很好,但不可读,区分每条线的颜色很差。根据我的讲师的可视化,他使用了 Wolfram。
我怎样才能使用 Python 实现这一点,或者我的方法有更好的替代方案吗?
这是我的代码
#To make the legend readable we reduce the font size
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('small')
fig, ax = plt.subplots(figsize = (20,16))
df1.groupby(['Year','Country',]).sum().unstack().plot(ax = ax)
ax.set_yscale("log")
ax.set_ylim(1,300000)
plt.ylabel('Year')
plt.xlabel('Total Value')
plt.title('Food Production in Africa over the Years')
plt.legend(title='Countries', bbox_to_anchor=(1.05, 1), loc='upper left',
prop=fontP)
我的讲师使用 Wolfram 进行可视化
我的尝试
【问题讨论】:
-
欢迎来到 Stackoverflow。你的尝试很好。您也应该在上面发布您的 python 代码,以便这里的用户可以提供建议。或者您是否在询问可用于这些数据的其他图形替代方案?
标签: python data-visualization linegraph