Home > Enterprise >  Issues Using geoplot.kdeplot with geopandas
Issues Using geoplot.kdeplot with geopandas

Time:09-18

Example of a kdeplot from the geopandas docs

Im trying to make a kdeplot using geopandas.

this is my code:

Downloading shape file

URL = "https://data.sfgov.org/api/geospatial/wkhw-cjsf?method=export&format=Shapefile"
response = requests.get(URL)
open('pd_data.zip', 'wb').write(response.content)

with zipfile.ZipFile('./pd_data.zip', 'r') as zip_ref:
    zip_ref.extractall('./ShapeFiles')

Making the geopandas data frame

data = train.groupby(['PdDistrict']).count().iloc[:,0]
data = pd.DataFrame({ "district": data.index,
                    "incidences": data.values})

california_map = str(list(pathlib.Path('./ShapeFiles').glob('*.shp'))[0])

gdf = gdp.read_file(california_map)
gdf = pd.merge(gdf, data, on = 'district')

Note: I didn't include the link to the train set because it's not important for this question(use any data you want)

This is the part that I don't get, what arguments should I pass to the kdeplot function, like where I pass the shape file and where I pass the data?

ax = gplt.kdeplot(
    data, clip=gdf.geometry,
    shade=True, cmap='Reds',
    projection=gplt.crs.AlbersEqualArea())
gplt.polyplot(boroughs, ax=ax, zorder=1)

CodePudding user response:

  • had a few challenges setting up an environment where I did not get kernel crashes. Used none wheel versions of shapely and pygeos
  • a few things covered in documentation enter image description here

  • Related