在散点图Python中绘制一年中的多个日期

时间:2018-11-26 16:41:04

标签: python python-3.x python-2.7 dataframe matplotlib

我有一些数据,这些数据具有我希望能够在散点图中自动拆分的样子,

Date            Level        Price
2008-01-01      56           11
2008-01-03      10           12
2008-01-05      52           13
2008-02-01      66           14
2008-05-01      20           10
..
2009-01-01      12           11
2009-02-01      70           11
2009-02-05      56           12
..
2018-01-01      56           10
2018-01-11      10           17
..

我唯一知道解决此问题的方法就是使用iloc手动选择并按如下所示查看数据框中的日期:

fig = plt.figure(figsize=(15,10))
ax1 = fig.add_subplot(111)

ax1.scatter(df.iloc[____, 1], df.iloc[_____, 2], s=10, c='r', marker="o", label='2008')
ax1.scatter(df.iloc[____, 1],df.iloc[____, 2], s=10, c='mediumblue', marker="o", label='2009')

.
.
. (for each year I want)

plt.ylabel('Level', fontsize=14)
plt.xlabel('Price', fontsize=14)
plt.legend(loc='upper left', prop={'size': 12});
plt.show()

但这需要很多时间。

我想在每个日期的年份中自动循环,并在颜色上按价格(Y)至价格(X)绘制不同的颜色给定年份,并为每年制作一个图例标签。

执行此操作的最佳策略是什么?

0 个答案:

没有答案