Python 按时间分组值的颜色散点图

Python 按时间分组值的颜色散点图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有一个数据框dfp,其中的列包括saledate(在DateTime中)、days\u-to\u-sell(作为int)和price(作为int)。使用以下代码 import pandas as pd dfp_week = dfp.groupby(pd.TimeGrouper(key='saledate', freq='W')).mean() fig, ax = plt.subplots() ax.scatter(dfp['saledate'].values, dfp['price']/1

我有一个数据框
dfp
,其中的列包括
saledate
(在DateTime中)、
days\u-to\u-sell
(作为
int
)和
price
(作为
int
)。使用以下代码

import pandas as pd
dfp_week = dfp.groupby(pd.TimeGrouper(key='saledate', freq='W')).mean()

fig, ax = plt.subplots()

ax.scatter(dfp['saledate'].values, dfp['price']/1000.0, c=dfp['days_to_sell'].values)

ax.plot_date(dfp_week.index, dfp_week['price']/1000.0, 'r-')
xmin,xmax=plt.xlim()
plt.xlim([datetime.datetime(2015,1,1), xmax])

ax.set_xlabel('Date of sale')
ax.set_ylabel('Most recent asking price (1,000 euros)')
plt.title('Property sales in Amsterdam')
fig.autofmt_xdate()
我生成以下绘图:

这些点按销售天数上色,但有太多的点无法在数据中看到趋势。另一方面,如果我将
days\u to\u sell
自身与其每周平均值一起绘制

fig2, ax2 = plt.subplots()
plt.plot(dfp['saledate'],dfp['days_to_sell'].values,'.')
plt.plot_date(dfp_week.index, dfp_week['days_to_sell'].values,'r-')
plt.xlabel('Date of sale')
plt.ylabel('Days on the market')
plt.title('Time to sell')
plt.ylim([0,300])
fig2.autofmt_xdate()
我明白了

这表明近期房地产市场明显“升温”。我想用每周平均的
卖出时间
来给图中的所有点上色,而不是用单个值。我该怎么做