How to create a reusable basemap

微笑、不失礼 提交于 2019-12-19 03:13:44

问题


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:

  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!



来源:https://stackoverflow.com/questions/31133278/how-to-create-a-reusable-basemap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!