Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a reusable basemap

In continuation to my previous question: How to superimpose figures in matplotlib i would like to know how can one create a reusable basemap object. My problem is that a basemap is not a pyplot object, so the solution i received works well on figures / axes but not on basemap objects.

I tried to look around and find a solution, but couldn't find any, just discussions.

like image 965
Shai Efrati Avatar asked Nov 10 '22 10:11

Shai Efrati


1 Answers

Thanks to @JoeKington here and @EdSmith at How to superimpose figures in matplotlib, i was able to understand how to achieve what i wanted: reuse basemap objects and pass them around.

I made it this way:

  1. Created a base_map.py that has two functions: plot() that create a map object and draw some properties and another one, set_a_map() that create an empty map object.
  2. In the other modules i added to the plot functions a map=None property, and in each function i added a:

    if not map:  
        map = base_map.set_a_map()
    

    So that in case that no map object being passed to the other function, the function will create a new map object.

  3. In my plot functions, instead of using plt.imshow(...) for example, i'm using map.imshow(...). This way my data will be plot over a map.

Thank you for the patience and the really helpful comments!

like image 88
Shai Efrati Avatar answered Nov 14 '22 21:11

Shai Efrati