我无法强制zorder与matplolib底图和箭袋叠加绘制。
这是我正在做的事(Mac OsX,python 3.6)
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt latmin = -33.496886 latmax = -33.388023 lonmin = -70.692902 lonmax = -70.515747 map_s = Basemap(projection = 'merc', epsg=4326, llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, lat_ts=20, resolution='i') map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True) x, y, u, v = -70.564464625, -52.011810175, -0.2569774, -0.1781287 lon, lat = map_s(float(x), float(y)) map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100) plt.xlabel('Longitude') plt.ylabel('Latitude') plt.show()当我这样做时,卫星图像位于红色矢量的上方,而我希望看到相反的位置,在卫星图像的顶部有红色矢量。
我也试过(ex1)
plt.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100)而不是(ex2)
map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100)但结果是一样的。 我错过了什么,我做错了什么?
(小问题:当我删除零件
map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True)我可以看到矢量(ex1),但不能(ex2)。 情况应该如此)
非常感谢!
I cannot force the zorder for an overplot with matplolib basemap and the quiver.
Here is what I am doing (Mac OsX, python 3.6)
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt latmin = -33.496886 latmax = -33.388023 lonmin = -70.692902 lonmax = -70.515747 map_s = Basemap(projection = 'merc', epsg=4326, llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, lat_ts=20, resolution='i') map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True) x, y, u, v = -70.564464625, -52.011810175, -0.2569774, -0.1781287 lon, lat = map_s(float(x), float(y)) map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100) plt.xlabel('Longitude') plt.ylabel('Latitude') plt.show()When I do this, the satellite image is above the red vector while I wish to see the opposite, having the red vector on top of the satellite image.
I have also tried to do (ex1)
plt.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100)instead of (ex2)
map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r', zorder=100)but the result is the same. What am I missing, what am I doing wrong?
(Minor question: When I remove the part
map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True)I can see the vector when I do (ex1) but not (ex2). Should it be the case)
Thanks a lot!
最满意答案
箭头箭头的绘图位置不受限制,其大小太大。 Zorder不相关,默认值很好。 以下代码调整要在图像限制内绘制的箭头的位置和大小。
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt latmin = -33.496886 latmax = -33.388023 lonmin = -70.692902 lonmax = -70.515747 map_s = Basemap(projection = 'merc', epsg=4326, llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, lat_ts=20, resolution='i') map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True) # Out of limits x,y,u,v=-70.5644,-52.0118,-0.2569,-0.1781 x, y, u, v = -70.55, -33.4, -0.05, -0.05 lon, lat = map_s(float(x), float(y)) map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r') plt.xlabel('Longitude') plt.ylabel('Latitude') plt.show()
你将不得不决定要调整哪个,图像限制或箭袋。
Your plot location of quiver arrow is out of bound, and its size is too big. Zorder is not relevant, the default value is fine. Here is the code that adjust the position and size of the arrow to plot within the image limits.
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt latmin = -33.496886 latmax = -33.388023 lonmin = -70.692902 lonmax = -70.515747 map_s = Basemap(projection = 'merc', epsg=4326, llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, lat_ts=20, resolution='i') map_s.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=200, verbose=True) # Out of limits x,y,u,v=-70.5644,-52.0118,-0.2569,-0.1781 x, y, u, v = -70.55, -33.4, -0.05, -0.05 lon, lat = map_s(float(x), float(y)) map_s.quiver(lon, lat, float(u), float(v), width=0.005, scale_units='xy', scale=1, color='r') plt.xlabel('Longitude') plt.ylabel('Latitude') plt.show()You will have to decide which to adjust, the image limits or the quiver's.
更多推荐
发布评论