【发布时间】:2017-08-29 20:39:31
【问题描述】:
为了自己的学习目的,我正在使用住房数据集,我希望能够将我的地块叠加在地图上,以便更好地了解“热点”。
我的代码如下:
housing = pd.read_csv('https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv')
plt.figure()
housing.plot(x='longitude', y='latitude', kind='scatter', alpha=0.4,
s= housing['population']/100, label='population', figsize=(10,7),
c= 'median_house_value', cmap=plt.get_cmap('jet'), colorbar=True, zorder=5)
plt.legend()
plt.show()
我保存为'California.png'的图片
这是我尝试过的:
img=imread('California.png')
plt.figure()
plt.imshow(img,zorder=0)
housing.plot(x='longitude', y='latitude', kind='scatter', alpha=0.4,
s= housing['population']/100, label='population', figsize=(10,7),
c= 'median_house_value', cmap=plt.get_cmap('jet'), colorbar=True, zorder=5)
plt.legend()
plt.show()
但这只是给了我两个情节。我试过切换索引无济于事。
有没有一种简单的方法可以做到这一点?谢谢。
编辑:使用@nbeuchat 下面的代码:
plt.figure(figsize=(10,7))
img=imread('California.png')
plt.imshow(img,zorder=0)
ax = plt.gca()
housing.plot(x='longitude', y='latitude', kind='scatter', alpha=0.4,
s= housing['population']/100, label='population', ax=ax,
c= 'median_house_value', cmap=plt.get_cmap('jet'), colorbar=True,
zorder=5)
plt.legend()
plt.show()
我得到以下情节:
【问题讨论】: