Python 地质地块赢得';t标绘地质标线对象

Python 地质地块赢得';t标绘地质标线对象,python,gis,geopandas,pysal,Python,Gis,Geopandas,Pysal,我使用geopandas和上一次选举中每个县的投票率导入了威斯康星州县的shapefile。我现在正试图使用沃罗诺细分法将威斯康星州划分为几个街区,每个县的投票份额。我想使用geoplot.voronoi来执行此操作,但是geoplot无法绘制地图,并且在我对shapefile数据调用geoplot.voronoi时崩溃 下面的代码成功地生成了投票份额的映射 import pandas as pd import matplotlib.pyplot as plt import geopandas

我使用
geopandas
和上一次选举中每个县的投票率导入了威斯康星州县的shapefile。我现在正试图使用沃罗诺细分法将威斯康星州划分为几个街区,每个县的投票份额。我想使用
geoplot.voronoi
来执行此操作,但是
geoplot
无法绘制地图,并且在我对shapefile数据调用
geoplot.voronoi
时崩溃

下面的代码成功地生成了投票份额的映射

import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gp

wi = gp.GeoDataFrame.from_file('./data/shape/Wards_111312.shp')
elec_dat = pd.read_csv('./data/wi_2014_heda.csv')

wi['vrat'] = elec_dat['g2014_SOS_rv']
wi['vdat'] = elec_dat['g2014_SOS_dv']
wi['mr'] = (wi['vdat'] - wi['vrat']) / ((wi['vdat'] + wi['vrat']))
wi['mr'] = wi['mr'].fillna(0)

wi.plot(column = 'mr', cmap='OrRd')

但是,当我尝试使用
geoplot
绘制相同的东西时,我得到一张空白图像(下面明显的空白就是图像)

此外,如果我尝试绘制Voronoi细分:

ax = geoplot.voronoi(
    wi.sample(1000),
    hue='mr', cmap='Reds', scheme='fisher_jenks',
    clip=wi.geometry,
    linewidth=0)
geoplot.polyplot(wi, ax=ax)
我得到以下错误:

/home/rtse/anaconda3/envs/gerry/lib/python3.6/site-packages/pysal/__init__.py:65: VisibleDeprecationWarning: PySAL's API will be changed on 2018-12-31. The last release made with this API is version 1.14.4. A preview of the next API version is provided in the `pysal` 2.0 prelease candidate. The API changes and a guide on how to change imports is provided at https://pysal.org/about
  ), VisibleDeprecationWarning)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-5ed5e333efcd> in <module>
      7     hue='mr', cmap='Reds', scheme='fisher_jenks',
      8     clip=wi.geometry,
----> 9     linewidth=0)
     10 geoplot.polyplot(wi, ax=ax)
     11 

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in voronoi(df, projection, edgecolor, clip, hue, scheme, k, cmap, categorical, vmin, vmax, legend, legend_kwargs, legend_labels, extent, figsize, ax, **kwargs)
   2126 
   2127     # Finally we draw the features.
-> 2128     geoms = _build_voronoi_polygons(df)
   2129     if projection:
   2130         for color, geom in zip(colors, geoms):

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in _build_voronoi_polygons(df)
   2628     """
   2629     from scipy.spatial import Voronoi
-> 2630     geom = np.array(df.geometry.map(lambda p: [p.x, p.y]).tolist())
   2631     vor = Voronoi(geom)
   2632 

~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/series.py in map(self, arg, na_action)
   2996         """
   2997         new_values = super(Series, self)._map_values(
-> 2998             arg, na_action=na_action)
   2999         return self._constructor(new_values,
   3000                                  index=self.index).__finalize__(self)

~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/base.py in _map_values(self, mapper, na_action)
   1002 
   1003         # mapper is a function
-> 1004         new_values = map_f(values, mapper)
   1005 
   1006         return new_values

pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in <lambda>(p)
   2628     """
   2629     from scipy.spatial import Voronoi
-> 2630     geom = np.array(df.geometry.map(lambda p: [p.x, p.y]).tolist())
   2631     vor = Voronoi(geom)
   2632 

AttributeError: 'MultiPolygon' object has no attribute 'x'
/home/rtse/anaconda3/envs/gerry/lib/python3.6/site packages/pysal/__init__;.py:65:VisibleDeprecationWarning:pysal的API将于2018年12月31日更改。使用此API制作的最后一个版本是1.14.4版。下一个API版本的预览在'pysal`2.0 prerelease候选者中提供。API的更改以及如何更改导入的指南在https://pysal.org/about
),VisibleDepractionWarning)
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在里面
7色调class='mr',cmap class='Reds',图案class='fisher_-jenks',
8剪辑=wi几何体,
---->9线宽=0)
10地质地块。多地块(wi,ax=ax)
11
voronoi中的~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py
2126
2127#最后我们绘制特征。
->2128几何=构建多边形(df)
2129如果预测:
2130颜色,拉链几何图形(颜色,几何图形):
~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in\u build\u voronoi\u polygons(df)
2628     """
2629来自scipy.spatial import Voronoi
->2630 geom=np.array(df.geometry.map(lambda p:[p.x,p.y]).tolist())
2631 vor=Voronoi(geom)
2632
地图中的~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/series.py(self、arg、na_动作)
2996         """
2997新值=超级(系列、自).\u映射\u值(
->2998 arg,na_动作=na_动作)
2999返回self.\u构造函数(新的\u值,
3000索引=self.index.\uuuu最终确定\uuuuu(self)
~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/base.py in\u map\u值(self、mapper、na\u action)
1002
1003#映射器是一个函数
->1004新值=映射(值,映射器)
1005
1006返回新的_值
pandas/_libs/src/inference.pyx在pandas中。_libs.lib.map_infere()
~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in(p)
2628     """
2629来自scipy.spatial import Voronoi
->2630 geom=np.array(df.geometry.map(lambda p:[p.x,p.y]).tolist())
2631 vor=Voronoi(geom)
2632
AttributeError:“MultiPolygon”对象没有属性“x”
我是否缺少在
geoplot
中绘制几何图形所需的步骤?我遵循了这一步骤,但他们从
geopandas.dataset
加载数据,而不是提供自己的形状文件。我做错了什么


提前感谢您提供的所有帮助!

我刚刚遇到了与此类似的问题,发现我的问题是我的LAT和LON值是向后的。
shapely.Point tuples
必须是(LON,LAT)


空白绘图的另一个可能原因是,绘图根本不是空白的,它只是一个非常大区域的地图。我认为这不太可能用于绘图,但您可以通过将一个包含最小和最大LON和LAT值的元组传递给gplt.polyplot()中的
范围
变量来检查这一点.

AttributeError:“MultiPolygon”对象没有属性“x”
使我相信,细分需要传递点几何体而不是多边形。请尝试使用每个多边形的质心。
/home/rtse/anaconda3/envs/gerry/lib/python3.6/site-packages/pysal/__init__.py:65: VisibleDeprecationWarning: PySAL's API will be changed on 2018-12-31. The last release made with this API is version 1.14.4. A preview of the next API version is provided in the `pysal` 2.0 prelease candidate. The API changes and a guide on how to change imports is provided at https://pysal.org/about
  ), VisibleDeprecationWarning)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-5ed5e333efcd> in <module>
      7     hue='mr', cmap='Reds', scheme='fisher_jenks',
      8     clip=wi.geometry,
----> 9     linewidth=0)
     10 geoplot.polyplot(wi, ax=ax)
     11 

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in voronoi(df, projection, edgecolor, clip, hue, scheme, k, cmap, categorical, vmin, vmax, legend, legend_kwargs, legend_labels, extent, figsize, ax, **kwargs)
   2126 
   2127     # Finally we draw the features.
-> 2128     geoms = _build_voronoi_polygons(df)
   2129     if projection:
   2130         for color, geom in zip(colors, geoms):

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in _build_voronoi_polygons(df)
   2628     """
   2629     from scipy.spatial import Voronoi
-> 2630     geom = np.array(df.geometry.map(lambda p: [p.x, p.y]).tolist())
   2631     vor = Voronoi(geom)
   2632 

~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/series.py in map(self, arg, na_action)
   2996         """
   2997         new_values = super(Series, self)._map_values(
-> 2998             arg, na_action=na_action)
   2999         return self._constructor(new_values,
   3000                                  index=self.index).__finalize__(self)

~/anaconda3/envs/gerry/lib/python3.6/site-packages/pandas/core/base.py in _map_values(self, mapper, na_action)
   1002 
   1003         # mapper is a function
-> 1004         new_values = map_f(values, mapper)
   1005 
   1006         return new_values

pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()

~/anaconda3/envs/gerry/lib/python3.6/site-packages/geoplot/geoplot.py in <lambda>(p)
   2628     """
   2629     from scipy.spatial import Voronoi
-> 2630     geom = np.array(df.geometry.map(lambda p: [p.x, p.y]).tolist())
   2631     vor = Voronoi(geom)
   2632 

AttributeError: 'MultiPolygon' object has no attribute 'x'