How to create a reusable base card

To continue my previous question: How to overlay numbers in matplotlib , I would like to know how to create a reusable basemap . My problem is that basemap not a pyplot object, so the resulting solution works well on figures / axes , but not on basemap objects.

I tried to look back and find a solution, but could not find a single one, just a discussion.

+5
source share
1 answer

Thanks to @JoeKington here and @EdSmith in How to Overlay Numbers in matplotlib , I was able to figure out how to achieve what I wanted: to reuse the base map objects and walk them around.

I did it like this:

  • Created base_map.py , which has two functions: plot() , which create a map object and draw some properties and others, set_a_map() , which create an empty map object.
  • In other modules, I added a map=None property to the chart functions, and in each function I added:

     if not map: map = base_map.set_a_map() 

    So, if the map object is not passed to another function, the function will create a new map object.

  • In my chart functions, instead of using plt.imshow(...) , for example, I use map.imshow(...) . Thus, my data will be displayed on the map.

Thanks for your patience and really useful comments!

+1
source

All Articles