Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫散点图类型错误_Python_Python 3.x_Pandas_Scatter Plot - Fatal编程技术网

Python 熊猫散点图类型错误

Python 熊猫散点图类型错误,python,python-3.x,pandas,scatter-plot,Python,Python 3.x,Pandas,Scatter Plot,我试图使用geopandas在一个shapefile中绘制点,但我一直遇到这样的问题 TypeError:必须首先为可映射设置_数组 每当我运行下面的代码时。当我删除colormap属性时,此错误消失。但是我想改变我的点的颜色,我认为colormap对此很有帮助 这是我的密码: import matplotlib.pyplot as plt import geopandas shapefile = geopandas.GeoDataFrame.from_file('file.shp') fi

我试图使用
geopandas
在一个shapefile中绘制点,但我一直遇到这样的问题

TypeError:必须首先为可映射设置_数组

每当我运行下面的代码时。当我删除
colormap
属性时,此错误消失。但是我想改变我的点的颜色,我认为
colormap
对此很有帮助

这是我的密码:

import matplotlib.pyplot as plt
import geopandas

shapefile = geopandas.GeoDataFrame.from_file('file.shp')

fig, ax = plt.subplots(1)

base = shapefile.plot(ax=ax)

df.plot.scatter('Long', 'Lat',  c=df['colC'], s=df['colD'], alpha=0.7, ax=base, colormap='viridis')

您可以尝试直接调用
matplotlib
。我没有您的数据集可用于尝试此操作,但请尝试以下操作:

from operator import itemgetter

import geopandas
import matplotlib.pyplot as plt

shapefile = geopandas.GeoDataFrame.from_file('file.shp')

fig, ax = plt.subplots()

shapefile.plot(ax=ax)

x, y, c, s = itemgetter('Long', 'Lat', 'colC', 'colD')(df)
ax.scatter(x, y, c=c, s=s, cmap='viridis')

'colC'
中存储的类型是什么?浮点数…如果将
c=df['colC']
更改为
c='colC'
,同时保持
colormap
参数不变,会发生什么情况?我遇到相同的错误:(很高兴听到这个消息!我刚刚意识到它也可能是您对
ax=base
的规范。我的猜测是
GeoDataFrame.plot
不会返回
ax
对象。最好将相同的
Axes
对象显式传递给您感兴趣调用的每个绘图调用。