0

i was able to create a choropleth map using plotly-express and a geojson file and a datasource (*.csv-file). The data from the *.csv file is plotted on the geojson-file. See below code i used.

But what if the data is allready in the geojson file? So the *.geojson file has the geomotrie and also the values i wan't to represent. How can i point plotly-express to that datasource (geojson-file)?

Thnx in advanced.

# import json
with urlopen('https://geodata.xxxxxxxxx') as response:
counties = json.load(response)

# import pandas as pd
df = pd.read_csv("test.csv",
               dtype={"statnaam": str})

fig = px.choropleth_mapbox(df, geojson=counties, locations='statnaam', color='unempl',
                       color_continuous_scale="Viridis",
                       range_color=(0, 80),
                       mapbox_style="carto-positron")
HzM74
  • 71
  • 7
  • Map visualization associates map information with its associated data in relevant column data. This is imaginary, but I guess I will have to take the necessary data from the geojson file and turn it into a data frame. Isn't it essential to present the geojson data in this kind of question? – r-beginners Dec 28 '21 at 12:52
  • Thnx for the response. How would you extact the data from the geojson? – HzM74 Dec 28 '21 at 13:36
  • I find [this answer](https://stackoverflow.com/questions/42753745/how-can-i-parse-geojson-with-python) to be very helpful. From this answer, I think that if we combine the extracted data into a data frame, we can display the map with the current code. – r-beginners Dec 28 '21 at 13:46
  • Thnx for pointing me in the right way. It answered my question. Thnx. – HzM74 Dec 28 '21 at 19:05

0 Answers0