熊猫散点图TypeError

时间:2018-10-23 17:25:15

标签: python python-3.x pandas scatter-plot

我正在尝试使用geopandas在shapefile中绘制点,并且一直遇到

  

TypeError:您必须首先为可映射设置set_array

每当我运行以下代码时。当我删除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')

1 个答案:

答案 0 :(得分:0)

您可以尝试直接致电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')
相关问题