gpt4 book ai didi

python - 类型错误 : ufunc 'sqrt' not supported for the input types when plotting a colormap in basemap

转载 作者:行者123 更新时间:2023-12-02 00:19:07 24 4
gpt4 key购买 nike

我想使用颜色图绘制有关房价与地理坐标之间关系的散点图。

from mpl_toolkits.basemap import Basemap


lats = df['latitude'].as_matrix()
lons = df['longitude'].as_matrix()

zoom_scale = 0

bbox = [np.min(lats)-zoom_scale,np.max(lats)+zoom_scale,\
np.min(lons)-zoom_scale,np.max(lons)+zoom_scale]

plt.figure()

m = Basemap(projection='merc',llcrnrlat=bbox[0],urcrnrlat=bbox[1],\
llcrnrlon=bbox[2],urcrnrlon=bbox[3],resolution='i')

m.drawcoastlines()
m.drawrivers()

x,y = m(lons,lats)
cm = plt.cm.get_cmap('coolwarm')
plot = m.scatter(x,y,'o',c = df['price'],cmap=cm)
plt.colorbar(plot)
plt.title("House Price with Geographic Coordinate")
plt.show()

控制台给出类型错误:


中的 TypeError Traceback(最近调用最后)
     28 x,y = m(lons,lats)
29 cm = plt.cm.get_cmap('coolwarm')
---> 30 plot = m.scatter(x,y,'o',c = df['price'],cmap=cm)
31 plt.colorbar(plot)
32 plt.title("House Price with Geographic Coordinate")

....

/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in set_sizes(self, sizes, dpi)
872 self._sizes = np.asarray(sizes)
873 self._transforms = np.zeros((len(self._sizes), 3, 3))
--> 874 scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor
875 self._transforms[:, 0, 0] = scale
876 self._transforms[:, 1, 1] = scale

TypeError:输入类型不支持 ufunc 'sqrt',根据转换规则 ''safe'' 无法将输入安全地强制转换为任何受支持的类型

我该如何解决这个问题?最好的问候

最佳答案

plt.scatter 行中取出 'o'

关于python - 类型错误 : ufunc 'sqrt' not supported for the input types when plotting a colormap in basemap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56115201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com