How to create a reusable basemap

徘徊边缘 提交于 2019-11-30 21:46:13
Shai Efrati

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!

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