# Is it possible to use custom GeoJson on go.Choropleth not plotly Express

**URL:** https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819
**Category:** 📊 Plotly Python
**Created:** [March 28, 2020, 10:53am UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819 "2020-03-28T10:53:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fbosler](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/fbosler/32/9799_2.png) [@fbosler](https://community.plotly.com/u/fbosler)
#### Post date: [March 28, 2020, 10:53am UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/1 "2020-03-28T10:53:09Z")

</div>

I have built a dash app where I am plotting German Districts. Find Repo [here](https://github.com/FBosler/covid19-dash-app).

However, I need log scales (for the colors) and want to overwrite the hover box with actual numbers. I get the feeling this would be easier done with the old Plotly.

Current Visualization:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/3f8c0f6eeb7eff422b480015b4e96ae3331f7b55.png)

Ideally what I want to do is to have a visualization like [here](https://mfreeborn.github.io/blog/2020/03/15/interactive-coronavirus-map-with-jupyter-notebook) on a German level:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/cd3272d2ec90cf1f7975c91cfbf85129485e7f26.png)

---

<div class="post-metadata">

### Author: ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)
#### Post date: [March 28, 2020, 11:07am UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/2 "2020-03-28T11:07:44Z")

</div>

Hi @fbosler, two answers to your question 🙂

- yes, the `go.Choropleth` trace has `geojson` and `featureidkey` attributes which you can use as in the `px` function, see [https://plotly.com/python-api-reference/generated/plotly.graph\_objects.Choropleth.html](https://plotly.com/python-api-reference/generated/plotly.graph_objects.Choropleth.html) for the API documentation
- that said, you can also pass to `px.choropleth` the log of the values in the `color` argument of `px.choropleth`, and modify the hovertemplate to your taste using `fig.update_traces`. You can also tune the ticks of the colorbar, or just use a prefix like what is one [here](https://github.com/covid19-dash/covid-dashboard/blob/master/make_figures.py#L48), corresponding to [this dashboard](https://covid19-dash.github.io/)

---

<div class="post-metadata">

### Author: ![fbosler](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/fbosler/32/9799_2.png) [@fbosler](https://community.plotly.com/u/fbosler)
#### Post date: [March 28, 2020, 12:01pm UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/3 "2020-03-28T12:01:30Z")

</div>

Hi @Emmanuelle ! thx for the reply. Amazing dashboard btw. did you code it yourself?  
How did you deploy it? For ease of use, I deployed mine via AWS/serverless. But it’s super slow and I am running into payload size restrictions now.

---

<div class="post-metadata">

### Author: ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)
#### Post date: [March 28, 2020, 1:19pm UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/4 "2020-03-28T13:19:12Z")

</div>

if the callbacks are slow you can try to write them as client-side callbacks (see [https://dash.plotly.com/performance](https://dash.plotly.com/performance) for more details). For this specific dashboard we wrote everything with client-side callbacks (and we also transformed the app into static html pages because we wanted to host it under Github pages but this is very hacky I would not recommend it).

---

<div class="post-metadata">

### Author: ![fbosler](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/fbosler/32/9799_2.png) [@fbosler](https://community.plotly.com/u/fbosler)
#### Post date: [March 28, 2020, 2:28pm UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/5 "2020-03-28T14:28:57Z")

</div>

Heya Emmanuelle,

not it seems like my provided geojson doesn’t do anything (as in a sense, that it still shows the world map). Where am I going wrong here?

```auto
## imports
from urllib.request import urlopen
import pandas as pd
import plotly.graph_objects as go

df = pd.read_csv('https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/data.csv')

def fetch_counties():
    URL = "https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/counties.json"
    with urlopen(URL) as response:
        counties = json.load(response)
    return counties

counties = fetch_counties()

fig = go.Figure(data=go.Choropleth(
    geojson=counties,
    locations = df[df['infected'] != 0]['Landkreis'],
    featureidkey="properties.NAME_3"
))

fig.show()

```

---

<div class="post-metadata">

### Author: ![fbosler](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/fbosler/32/9799_2.png) [@fbosler](https://community.plotly.com/u/fbosler)
#### Post date: [March 29, 2020, 10:34am UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/6 "2020-03-29T10:34:01Z")

</div>

@Emmanuelle Could you give me a pointer how to make the Choropleth work with regions that is not the US? Would be really appreciated.  
Cheers

---

<div class="post-metadata">

### Author: ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)
#### Post date: [March 29, 2020, 1:38pm UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/7 "2020-03-29T13:38:08Z")

</div>

Hi @fbosler it does not work because you did not pass which information should be color-coded. Below are two working examples, one with `go.Choropleth` and the other one with `px.choropleth`.

```auto
from urllib.request import urlopen
import pandas as pd
import numpy as np
import json
import plotly.graph_objects as go

df = pd.read_csv('https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/data.csv')

def fetch_counties():
    URL = "https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/counties.json"
    with urlopen(URL) as response:
        counties = json.load(response)
    return counties

counties = fetch_counties()

fig = go.Figure(data=go.Choropleth(
    geojson=counties,
    z=np.log10(df['infected']),
    locations = df['Landkreis'],
    featureidkey="properties.NAME_3"
))
fig.update_geos(fitbounds="locations")

fig.show()

```

or

```auto
import plotly.express as px
import numpy as np
fig = px.choropleth(df, geojson=counties, locations='Landkreis', 
                              color=np.log10(df['infected']),
                              featureidkey="properties.NAME_3")
fig.update_geos(fitbounds="locations")
fig.show()

```

---

<div class="post-metadata">

### Author: ![fbosler](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/fbosler/32/9799_2.png) [@fbosler](https://community.plotly.com/u/fbosler)
#### Post date: [March 29, 2020, 2:29pm UTC](https://community.plotly.com/t/is-it-possible-to-use-custom-geojson-on-go-choropleth-not-plotly-express/36819/8 "2020-03-29T14:29:03Z")

</div>

> [@Emmanuelle](#):
>
> z=np.log10(df[‘infected’]),

Ahhh, you are amazing, really appreciate the help!

Cheers  
Fabian
