如何创建可重复使用的底图 [英] How to create a reusable basemap
问题描述
在继续我的上一个问题:如何在matplotlib中叠加数字我想知道如何创建一个可重用的basemap
对象.
我的问题是basemap
不是pyplot
对象,因此我收到的解决方案在figures / axes
上效果很好,但在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.
推荐答案
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.
我是这样做的:
- 创建了一个具有两个功能的
base_map.py
:plot()
创建一个地图对象并绘制一些属性,另一个set_a_map()
创建一个空地图对象. -
在我添加到绘图功能的其他模块中,添加了
map=None
属性,在每个功能中,我添加了:
- 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. 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.
在我的绘图功能中,例如,我使用的是map.imshow(...)
,而不是使用plt.imshow(...)
.这样,我的数据将被绘制在地图上.
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!
这篇关于如何创建可重复使用的底图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!