Black Lives Matter. Please consider donating to Black Girls Code today.

Custom GeoJson Issue: drawing boundary of last value and colouring all the plot with same colour


When I try to plot a plotly express choropleth map, I get a problem when plotly loads my custom GeoJson (I am pulling this form th UK’s official open data portal (see link in code snippet below)

Here is my code and I have attached the dummy dataset I am using.

The problem is that I see that the data is showing when I hover and only one of the boundaries have been drawn. The rest of the screen seems to have been filled by the values.

import pandas as pd
import plotly
import numpy as np

from urllib.request import urlopen
import json
with urlopen('') as response:
    counties = json.load(response)
df = pd.read_excel('testdata.xlsx',dtype={"cty19cd": str})

import as px

fig = px.choropleth(df, geojson=counties, locations='CODE', featureidkey="properties.cty19cd", color='VALUE',

fig.update_geos( fitbounds="locations", visible=True)

I have researched the web about the problem I am having. I found that the problem might be related to the incompatibility of the current GEOJSON standard and the D3 library that pltly uses under the hood, as discussed here.

Has anybody found a way to make plotly work with this uncompatible GeoJSONS?


It looks like a similar issue I ran into. I was able to fix this by reversing the polygons into clockwise order.

I’m sure there are plenty of ways to do this, but my method was to use Mapshaper and adding the gj2008 flag to the -o command.


Found the answer. I am going to put it here in case it helps people that encounter the same mistake.

There is a library called geojson_rewind that will let you “rewind” the GeoJson to the proper clockwise/counterclockwise direction.

The parameter rfc7946=False will ignore the current GeoJson specifications (see details here and use the previous 2008 version, which was clockwise

from geojson_rewind import rewind

#Load geo json
with urlopen('') as response:
    counties = json.load(response)


Then you can use that counties_corrected in the Plotly graph