Closed COYE-Coder closed 4 years ago
The issue appears to be with your GeoJSON file, which is "wound" the wrong way... see https://github.com/plotly/plotly.py/issues/2354#issuecomment-638742767 for a fix.
That solved it, thank you!
Here's more copy-pasteable code for starting from a badly-wound GeoPandas dataframe:
import json
import geojson_rewind
import geopandas as gpd
gdf = gpd.read_file("badly_wound.json")
gdf = gdf.set_geometry(
gpd.GeoDataFrame.from_features(
json.loads(
geojson_rewind.rewind(
gdf.to_json(),
rfc7946=False
)
)["features"]
).geometry
)
Here's more copy-pasteable code for starting from a badly-wound GeoPandas dataframe:
import json import geojson_rewind import geopandas as gpd gdf = gpd.read_file("badly_wound.json") gdf = gdf.set_geometry( gpd.GeoDataFrame.from_features( json.loads( geojson_rewind.rewind( gdf.to_json(), rfc7946=False ) )["features"] ).geometry )
This can sometimes produce dataframe with empty geometry column.
Somewhat more robust way:
igdf = gdf.set_geometry(
gpd.GeoDataFrame.from_features(
json.loads(
geojson_rewind.rewind(
gdf.to_json(),
rfc7946=False
)
)["features"]
).geometry.values
)
Tested on:
I am trying to create a choropleth using
plotly.express
. The figure is able to load, but it only shows one color. I can mouse over each feature and it displays the relevant information, but not in variable color. This implies that it is reading the geojson but not displaying properly. Here is my stackoverflow thread I created earlier.I am using the
featureidkey
parameter with a geojson (hucs) that should match with the DataFrame (predictions).Here is predictions:
And here is the code for reading in the geojson (hucs):
I followed the example here to index by geojson properties:
And here is what the output shows. Note that mouse-over shows relevant information, but no colors are displayed:
My csv and geojson are available for download here.
Many thanks in advance for the help!