Skip to content

Caching tiles not working as expected #2578

@guidocioni

Description

@guidocioni

I have a script making thousands of plots in parallel. The main function prepares the matplotlib axis and a background (using mapbox tiles), then every worker adds data on the plot and saves the picture.

Here is a pseudo-code example

def main():
  ...
  tile_source = cimgt.MapboxTiles(
      access_token=os.environ["MAPBOX_KEY"], map_id="dark-v10", cache=True
  )
  fig, axis = plt.subplots(
      1, 1, subplot_kw=dict(projection=tile_source.crs), figsize=(12, 12)
  )
  axis.add_image(tile_source, 6, interpolation="spline36")
  ...

# Spawns N concurrent processes with plotting function 
def plotting_function():
  ...
  axis.scatter()
  ...
  plt.savefig()

It seems that, even if I'm using caching, cartopy is trying to request the same tile multiple times, making a lot of requests to the server. I just realized this because of my mapbox account billing...

Why is this not working? what am I doing wrong? can't I just fetch the tile at the beginning when setting the axis and forget about it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions