Black Lives Matter. Please consider donating to Campaign Zero's mission of ending police violence in America.
https://www.joincampaignzero.org

Why is Plotly downloading so much data just to make some PNG files?

See code below. I have all the data I need downloaded locally already (geoJSON, population data, etc) - I load all the data from local files.

After data is cleaned, I end up calling px.choropleth_mapbox() hundreds of times in a loop (code below) to make a bunch of PNG files, each representing a different time slice of the data. I have multiple workers, one per CPU. The basic sequence is:

fig = px.choropleth_mapbox()
fig.update_layout()
fig.write_image()

While the loop is running, I’ve noticed my system is downloading a lot of stuff off the Internet - it starts when the Plotly loop begins, and it stops when the Plotly loop ends. It must be downloading the same thing over and over, because I always represent the same exact map, just with different data. This is slow and wasteful.

Is there a way to make Plotly work offline? Barring that, is there at least some way to cache previous downloads, so as to save bandwidth? (and presumably speed up my code)

Actual code:

fig = px.choropleth_mapbox(
    daydf,
    geojson=geos,
    featureidkey=fidkey,
    locations=area_unit,
    color=day,
    range_color=[bar_ticks[0][0], bar_ticks[0][-1]],
    color_continuous_scale="Inferno",
    center={'lat': map_geom[0], 'lon': map_geom[1] },
    zoom=map_geom[2],
    mapbox_style='carto-positron',
)

fig.update_layout(
    title_text=tt,
    title_x=title_geom[0],
    title_y=title_geom[1],
    title_font_size=title_geom[2],
    width=map_geom[3],
    height=map_geom[4],
    coloraxis_colorbar = {
        'tickmode': 'array',
        'title': '<b>' + data_type + '</b>',
        'tickvals': bar_ticks[0],
        'ticktext': bar_ticks[1],
    },
    margin={"r":0,"t":0,"l":0,"b":0},
)

map_file = 'frame-' + daystring.replace('/', '') + '.png'
map_full_path = os.path.join(map_folder, map_file)
fig.write_image(map_full_path, scale=1.0)