问题
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.
回答1:
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:
- Created a
base_map.pythat 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. In the other modules i added to the plot functions a
map=Noneproperty, 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.
In my plot functions, instead of using
plt.imshow(...)for example, i'm usingmap.imshow(...). This way my data will be plot over a map.
Thank you for the patience and the really helpful comments!
来源:https://stackoverflow.com/questions/31133278/how-to-create-a-reusable-basemap