I have a geodataframe with points within the united states. Each point has a geometry attribute as well as a value. I would like to plot a heat map based on these values on top the map of the united states using kdeplot. However, I'm not sure how gplt.kdeplot reads these data frames?

contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))
geometry = [Point(xy) for xy in zip(df.Lat, df.Long)]
crs = {'init': 'epsg:4326'}
gdf = GeoDataFrame(df["Gain1"], crs=crs, geometry=geometry)

ax = geoplot.kdeplot(
    gdf, clip=contiguous_usa.geometry,
    shade=True, cmap='Reds',
geoplot.polyplot(contiguous_usa, ax=ax, zorder=1)

First five rows of my geodataframe looks something like this, column "Gain1" are the values I want to use for the heatmap. enter image description here

  • Not sure what the gplt.kdeplot takes as the value column for each point – Houndbobsaw Aug 31 '19 at 12:28

gplt.kdeplot do not uses the value column for each point, but you can select the column row values of the GeoDataFrame for that as in KDEPlot of two NYC traffic accident contributing factors (qualitative values)

For quantitative values, I use one of my shapefiles

1) With all the values of a column (quantitative values DIP from 0 to 90)

gplt.pointplot(df, projection=gcrs.AlbersEqualArea(), hue='DIP', legend=True)

enter image description here

gplt.kdeplot(df,projection=gcrs.AlbersEqualArea(), cmap='Reds', shade=True, shade_lowest=True)

enter image description here

ax = gplt.kdeplot(df,projection=gcrs.AlbersEqualArea(), cmap='Reds')
gplt.pointplot(df, hue='DIP', legend=True, ax=ax)

enter image description here

2) analyze only DIP values > 75

ax= gplt.pointplot(df[df['DIP'] > 75], projection=gcrs.AlbersEqualArea(), hue='DIP', legend=True)
gplt.kdeplot(df[df['DIP'] > 75],cmap = 'Reds',ax=ax)

enter image description here

or only DIP values = 75

 gplt.kdeplot(df[df['DIP'] == 75],cmap = 'Reds',projection=gcrs.AlbersEqualArea(),shade=True, shade_lowest=False)

enter image description here

  • Thanks for your response, I looked at the nyc collisions data frame, could you please clarify what DIP is? – Houndbobsaw Aug 31 '19 at 15:35
  • I thought it would be a column of quantitative values in the nyc collisions data frame but it seems like it isn't? – Houndbobsaw Aug 31 '19 at 15:38
  • I use here my data for example and DIP is a quantitative data – gene Aug 31 '19 at 19:31
  • Sorry, maybe I'm too late, but did I understand correctly saying that KDE is not taking into account the values of the records, but their density? Using your dataset as example, If I have 1 observation very far any other observation with a DIP value of 90, and 1000 observations with low DIP = 1 close to each others, I would end up (with cmap = 'Reds') with a high density (dark red) for the latter and light red (low density) for the former with greater DPI? – umbe1987 Apr 26 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.