Matplotlib 底图:放大正交投影
Matplotlib basemap: zoom into orthographic projection
我正在尝试在正射投影中绘制一个区域,以便将它与来自卫星的图像分层,就像这幅
所以我尝试放大像 here
这样的正交投影
使用此代码:
fig = plt.figure(figsize = (5,5))
map = Basemap(projection = 'ortho', lon_0 = 15, lat_0 = 68,\
resolution = 'c')
lllon = 7
urlon = 21
lllat = 67
urlat = 70
xmin, ymin = map(lllon, lllat)
xmax, ymax = map(urlon, urlat)
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
map.drawcoastlines(linewidth = .1)
map.drawmeridians(np.arange(-180,180,1), linewidth = .01)
map.drawparallels(np.arange(-80,80,.25), linewidth = .01)
还有一些用于绘制线条,但这会导致图像的中心和比例正确但未裁剪到指定区域,如下所示:
有没有人知道如何解决这个问题?
问题中的代码生成完整的正交投影,如 the example 中所示。
The orthographic projection displays the earth as a satellite (in an orbit infinitely high above the earth) would see it.
为了只显示它的一部分,您可以将地图的边缘提供给 Basemap
调用。
不幸的是,you cannot use the lat/lon values for this,而是需要使用 x,y
值。
以下将因此起作用:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5))
m = Basemap(projection = 'ortho', lon_0 = 0, lat_0 = 10,
llcrnrx=-3000000, llcrnry=1000000, urcrnrx=3000000, urcrnry=6000000,
resolution = 'c')
m.drawcoastlines(linewidth = 1)
m.drawcountries()
plt.show()
this thread中显示了一个不同的选项,即在绘制地图后设置轴限制。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5))
map = Basemap(projection = 'ortho', lon_0 = 15, lat_0 = 68,\
resolution = 'l')
map.drawcoastlines(linewidth = 1)
map.drawmeridians(np.arange(-180,180,1), linewidth = 1)
map.drawparallels(np.arange(-80,80,.25), linewidth = 1)
lllon = 7
urlon = 21
lllat = 67
urlat = 70
xmin, ymin = map(lllon, lllat)
xmax, ymax = map(urlon, urlat)
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
plt.show()
我正在尝试在正射投影中绘制一个区域,以便将它与来自卫星的图像分层,就像这幅
所以我尝试放大像 here
这样的正交投影使用此代码:
fig = plt.figure(figsize = (5,5))
map = Basemap(projection = 'ortho', lon_0 = 15, lat_0 = 68,\
resolution = 'c')
lllon = 7
urlon = 21
lllat = 67
urlat = 70
xmin, ymin = map(lllon, lllat)
xmax, ymax = map(urlon, urlat)
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
map.drawcoastlines(linewidth = .1)
map.drawmeridians(np.arange(-180,180,1), linewidth = .01)
map.drawparallels(np.arange(-80,80,.25), linewidth = .01)
还有一些用于绘制线条,但这会导致图像的中心和比例正确但未裁剪到指定区域,如下所示:
有没有人知道如何解决这个问题?
问题中的代码生成完整的正交投影,如 the example 中所示。
The orthographic projection displays the earth as a satellite (in an orbit infinitely high above the earth) would see it.
为了只显示它的一部分,您可以将地图的边缘提供给 Basemap
调用。
不幸的是,you cannot use the lat/lon values for this,而是需要使用 x,y
值。
以下将因此起作用:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5))
m = Basemap(projection = 'ortho', lon_0 = 0, lat_0 = 10,
llcrnrx=-3000000, llcrnry=1000000, urcrnrx=3000000, urcrnry=6000000,
resolution = 'c')
m.drawcoastlines(linewidth = 1)
m.drawcountries()
plt.show()
this thread中显示了一个不同的选项,即在绘制地图后设置轴限制。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5))
map = Basemap(projection = 'ortho', lon_0 = 15, lat_0 = 68,\
resolution = 'l')
map.drawcoastlines(linewidth = 1)
map.drawmeridians(np.arange(-180,180,1), linewidth = 1)
map.drawparallels(np.arange(-80,80,.25), linewidth = 1)
lllon = 7
urlon = 21
lllat = 67
urlat = 70
xmin, ymin = map(lllon, lllat)
xmax, ymax = map(urlon, urlat)
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
plt.show()