I tried this example and it worked as shown in the link: GeoJSON issues with Plotly choropleth_mapbox.
Now I'm trying to use it in my Flask app without success and without any error message.
I prepared an example about what I'm doing:
import pandas as pd
import plotly.express as px
gjson={
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
1.398123838,
42.053625569
],
[
1.398415914,
42.053516811
],
[
1.398314792,
42.053358782
],
[
1.39808988,
42.053606388
],
[
1.398123838,
42.053625569
]
]
]
},
"properties": {
"id": 146,
"name": "17a"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
1.403772968,
42.061291146
],
[
1.40386018,
42.061350579
],
[
1.403935831,
42.061408731
],
[
1.406719063,
42.060329611
],
[
1.406713442,
42.060322418
],
[
1.406712334,
42.060313576
],
[
1.403772968,
42.061291146
]
]
]
},
"properties": {
"id": 163,
"name": "6"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
1.38425415,
42.041311214
],
[
1.384250799,
42.041343319
],
[
1.384284725,
42.141329127
],
[
1.38425415,
42.041311214
],
[
1.38425415,
42.041311214
]
]
]
},
"properties": {
"id": 164,
"name": "7a"
}
}
]
}
df = pd.DataFrame({'id':[146,163,164], 'name':['17a','6','7a'], 'value':[0.166639, 0.23465, 0.9343332]})
fig = px.choropleth_mapbox(df, geojson=gjson, color=df.value,
locations=df.name, featureidkey="properties.id",
center={"lat": 42.04951952053175, "lon": 1.3925319577334843},
mapbox_style="carto-positron", zoom=14)
fig.show()
When I put the json in geojson.io I can see the polygons:
However, fig.show() shows:
What an I doing wrong?