Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

How to create a choropleth with dash

$
0
0

another newbie question :smiley:
how can I create a chropleth map from a geojson and a csv file using dash :frowning: i created it using plotly express and when i try to add it as a dcc.graph components this the code from plotly express.

from urllib.request import urlopen

import plotly.offline as offline

import geojson

import pandas as pd

import plotly

import plotly as plt

import plotly.express as px

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

                #define data frame using pandas lib and display data for population in Tunisia 

df = pd.read_csv(“py/tngov -1.csv”)

print(df)

                        #Geojson data from url source 

with urlopen(‘http://www.openculture.gov.tn/dataset/70fd9b49-3925-477f-ae17-9d206d650aab/resource/4b3d85dd-a523-425c-b477-ab9fec6e51a0/download/decoupage.geojson’) as response:

cities = geojson.load(response)

print(cities[‘features’][0])

                                #choropleth map

fig= px.choropleth_mapbox(df, geojson=cities,locations=‘id’, color='population ',

color_continuous_scale=“Viridis”,hover_name = ‘deleg_na_1’, hover_data =[“gov_name_f”,“gov_id”,"population "],

labels={‘population’:‘population number’}, mapbox_style=“carto-darkmatter”,zoom=4,

center = {“lat”: 36.82189, “lon”:10.168969 })

fig.show()

plt.offline.plot(fig, filename = ‘map.html’)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images