python 中单个图形中的多图趋势
Multi-graph of trends in a single figure in python
我想在 python 中编写代码(使用 pandas 和 matplotlib)以在单个 window 中说明许多趋势。
我的初始数据集是这样的:
- 没有。年位年位年位
1 2000 1 2002 2 2005 3
2 1999 2 2003 2 2006 3
...
40 1999 3 2005 2 2007 1
其实每个数据点(1,2,3...40)在不同年份的1-3之间的位置是不一样的。我只是想展示他们持仓的趋势。可能它应该是每个人的简单折线图。我想在一个 window 中显示所有图表,以便我们可以比较不同数据点趋势的结果。知道我应该从哪里开始吗?在此先感谢您的帮助。
假设 df
是您的数据框,您可以使用此代码作为起点:
import pylab as plt
plt.figure("Unknown index")
for i, (name, row) in enumerate(df.iterrows()):
x, y = row[0::2], row[1::2]
plt.plot(x, y, '-*', label='Trend {}'.format(i))
plt.xticks(list(range(2000, 2017)))
plt.legend(loc=1)
plt.show()
我想在 python 中编写代码(使用 pandas 和 matplotlib)以在单个 window 中说明许多趋势。 我的初始数据集是这样的:
- 没有。年位年位年位
1 2000 1 2002 2 2005 3
2 1999 2 2003 2 2006 3
...
40 1999 3 2005 2 2007 1
其实每个数据点(1,2,3...40)在不同年份的1-3之间的位置是不一样的。我只是想展示他们持仓的趋势。可能它应该是每个人的简单折线图。我想在一个 window 中显示所有图表,以便我们可以比较不同数据点趋势的结果。知道我应该从哪里开始吗?在此先感谢您的帮助。
假设 df
是您的数据框,您可以使用此代码作为起点:
import pylab as plt
plt.figure("Unknown index")
for i, (name, row) in enumerate(df.iterrows()):
x, y = row[0::2], row[1::2]
plt.plot(x, y, '-*', label='Trend {}'.format(i))
plt.xticks(list(range(2000, 2017)))
plt.legend(loc=1)
plt.show()