正射投影Python [英] Orthographic projection Python
问题描述
我使用正投影投影来绘制地图. 我使用这个程序:
I use orthographic projection to plot maps. I use this programm:
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import os, sys
from sys import argv
import pylab
from mpl_toolkits.basemap import Basemap, shiftgrid
from matplotlib import mpl
from matplotlib import rcParams
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import matplotlib.patches as patches
import matplotlib.path as path
import matplotlib.dates as dt
from numpy import linalg
import netCDF4
import time
import datetime as d
import sys
import math
from mpl_toolkits.axes_grid1 import make_axes_locatable
from pylab import *
nc = netCDF4.Dataset ('tt.nc')
latvar = nc.variables['lat']
lat = latvar[:]
lon = nc.variables['lon'][:]
lat_0=30;lon_0=-25
m1 = Basemap(projection='ortho',lon_0=-25,lat_0=30,resolution='l')
m = Basemap(projection='ortho',lon_0=lon_0,lat_0=lat_0,resolution='l',\
llcrnrx=0.,llcrnry=0.,urcrnrx=m1.urcrnrx/2.,urcrnry=m1.urcrnry/2.)
X, Y = m(lon, lat)
O_x_1=nc.variables['O3']
h=9
lev=0
minOzone=0
maxOzone=40
plotOzone = m.pcolor(X,Y,O_x_1[h,lev,:,:],vmin=minOzone,vmax=maxOzone)
ax=colorbar(plotOzone, shrink=0.8,norm=(0,40))
m.drawcoastlines()
m.drawparallels(np.arange(-90.,120.,30.))
m.drawmeridians(np.arange(0.,420.,60.))
plt.show()
我该怎么做才能使地图居中 在欧洲?
What do I have to do to center my map on Europe ?
我已经玩过lat_0和lon_0,但是那还没有 给我想要的东西...
I have already played with lat_0 and lon_0 but that doesn't give what I want...
我无法添加数字来显示我所获得的 我想要什么...
I can't add figures to show what I obtained and what I would like...
谢谢!
推荐答案
lat_0和lon_0用于设置投影的原点,而不是地图的范围.通常情况下,失真最少的地方,因此您不希望原点与感兴趣区域的中心偏离太大.如果未指定范围,则底图将自动使地图围绕原点居中.
The lat_0 and lon_0 are for setting the origin of the projection, not the extent of the map. Usually the place with the least distortions so you dont want the origin to deviate too much from the center of your area of interest. Basemap will automatically center the map around the origin if you dont specify an extent.
如果知道要使用的范围(或边界框),则可以对地图进行居中(与原点不同).如果您知道正交"投影中的角坐标,则可以使用示例中的关键字(llcrnrx等).我对Basemap 1.0.6中的'llcrnrlon'关键字不太满意,它们似乎建议您可以输入地理坐标(纬度/经度).
Centering the map (different from its origin) can be done if you know what extent (or boundingbox) you want to use. If you know the corner coordinates in your 'ortho' projection you could use the keywords from your example (llcrnrx etc.). I have had no luck with the 'llcrnrlon' keywords in Basemap 1.0.6, they seem to suggest that you can input the coordinates of your extent in geographic (lat/lon).
另一种方法是抓住轴并手动设置x和y极限.好处是您可以在声明底图对象之后执行此操作,然后将其用于坐标转换.一个例子:
An alternative is to grab the axes and manually set an x- and y limit. A benefit is that you can do it after declaring the Basemap object which you can then use for coordinate transformation. An example:
from mpl_toolkits.basemap import Basemap
fig = plt.figure(figsize=(5,5))
m = Basemap(projection='ortho',lon_0=5,lat_0=35,resolution='l')
m.drawcoastlines()
m.drawparallels(np.arange(-90.,120.,15.))
m.drawmeridians(np.arange(0.,420.,30.))
# your extent in lat/lon (dec degrees)
ulx = -10
uly = 65
lrx = 65
lry = 35
# transform coordinates to map projection
xmin, ymin = m(ulx, lry)
xmax, ymax = m(lrx, uly)
# set the axes limits
ax = plt.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
请确保地图声明中的投影符合您的需求,我刚刚选择了一个位于欧洲范围内的原点.
Make sure the projection in the map declaration suites your needs, i have just picked an origin which falls within Europe.
这篇关于正射投影Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!