✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to reduce the html filesize of a mapbox choropleth plot

I am exporting a mapbox choropleth plot as a html file to embed on a webpage but the resultant html file produced by to_html() is very big (8.3 MB) is there any trick to reduce the file size of this html file without affecting it’s functionality.

Code:

import pandas as pd
import plotly.express as px
wiki_df =pd.read_html('https://en.wikipedia.org/wiki/COVID-19_pandemic_in_India')[6].dropna(how='all',axis=1)
wiki_df = wiki_df.drop(wiki_df.tail(2).index)
wiki_df.columns = ['States','Cases','Deaths','Recovered','Active']
wiki_df['Cases'] = wiki_df['Cases'].apply(lambda x: x.split('[')[0]).apply(lambda x: x.replace(',',''))
wiki_df['Deaths'] = wiki_df['Deaths'].apply(lambda x: x.split('[')[0]).apply(lambda x: x.replace(',',''))
wiki_df.drop(17,inplace=True)
wiki_df['Date'] = date.today()
india_geojson = json.load(open("/content/india_geojson.geojson", "r"))
state_id_map = {}
for feature in india_geojson["features"]:
    feature["id"] = feature["properties"]["state_code"]
    state_id_map[feature["properties"]["st_nm"]] = feature["id"]
wiki_df["id"] = wiki_df["States"].apply(lambda x: state_id_map[x])
wiki_df[['Active','Cases','Deaths','Recovered']] = wiki_df[['Active','Cases','Deaths','Recovered']].apply(pd.to_numeric)
fig = px.choropleth_mapbox(
    wiki_df,
    locations="id",
    geojson=india_geojson,
    color="Cases",
    hover_name="States",
    hover_data=["Cases","Active","Recovered","Deaths","Date"],
    title="Heat Map of Covid-19 Cases in India",
    mapbox_style="carto-positron",
    color_continuous_scale='Inferno_r',
    center={"lat": 24, "lon": 78},
    zoom=2.9,
    opacity=1,
)
fig.update_layout(height=700, width=950, font=dict(family="Arial, Helvetica, sans-serif",size=24,), title_x=0.5, coloraxis_colorbar=dict(title="No. of total cases"),) 
fig.write_html("map.html", include_plotlyjs="cdn")

link to the geojson file I used in my code