以下是代码:
import matplotlib.pylab as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
from scipy.interpolate import spline
equinoxAzi = np.array([90, 180, 270])
equinoxAlt = np.array([0, 38.7, 0])
summerAzi = np.array([45, 180, 315])
summerAlt = np.array([0, 62.1, 0])
winterAzi = np.array([135, 180, 225])
winterAlt = np.array([0, 16, 0])
# create instance of basemap, note we want a south polar projection to 90 = E
myMap = Basemap(projection='spstere',boundinglat=0,lon_0=180,resolution='l',round=True,suppress_ticks=True)
# set the grid up
gridX,gridY = 10.0,15.0
parallelGrid = np.arange(-90.0,90.0,gridX)
meridianGrid = np.arange(-180.0,180.0,gridY)
# draw parallel and meridian grid, not labels are off. We have to manually create these.
myMap.drawparallels(parallelGrid,labels=[False,False,False,False])
myMap.drawmeridians(meridianGrid,labels=[False,False,False,False],labelstyle='+/-',fmt='%i')
# we have to send our values through basemap to convert coordinates, note -winterAlt
equinoxX, equinoxY = myMap(equinoxAzi, -equinoxAlt)
summerX, summerY = myMap(summerAzi, -summerAlt)
winterX, winterY = myMap(winterAzi, -winterAlt)
# plot azimuth labels, with a North label.
ax = plt.gca()
ax.text(0.5,1.025,'N',transform=ax.transAxes,horizontalalignment='center',verticalalignment='bottom',size=25)
for para in np.arange(gridY,360,gridY):
x= (1.1*0.5*np.sin(np.deg2rad(para)))+0.5
y= (1.1*0.5*np.cos(np.deg2rad(para)))+0.5
ax.text(x,y,u'%i\N{DEGREE SIGN}'%para,transform=ax.transAxes,horizontalalignment='center',verticalalignment='center')
equinoxX_new = np.linspace(equinoxX.min(),equinoxY.max(),30)
equinoxY_smooth = spline(equinoxX, equinoxY, equinoxX_new)
summerX_new = np.linspace(summerX.min(), summerX.max(),30)
summerY_smooth = spline(summerX, summerY, summerX_new)
winterX_new = np.linspace(winterX.min(), winterX.max(),30)
winterY_smooth = spline(winterX, winterY, winterX_new)
myMap.plot(equinoxX_new, equinoxY_smooth, 'b')
myMap.plot(summerX_new, summerY_smooth, 'g')
myMap.plot(winterX_new, winterY_smooth/2, 'r')
myMap.plot(equinoxX, equinoxY, 'bo')
myMap.plot(summerX, summerY, 'go')
myMap.plot(winterX, winterY, 'ro')
plt.show()
我试图通过连接所有相同颜色的三个点(以蓝色,绿色和红色显示)绘制弧线。如何制作像第一张照片中的弧线?
答案 0 :(得分:2)
通过k
点创建度k
度的样条线不一定是个好主意。任何事都可能发生在那里。
由于scipy.interpolate.spline
无论如何都会被折旧,您可以使用scipy.interpolate.splev
和scipy.interpolate.splrep
并将样条线限制为k=2
度。 (尝试使用k=3
将导致错误,预计3分)
from scipy.interpolate import splev, splrep
equinoxX_new = np.linspace(equinoxX.min(),equinoxX.max(),30)
equinoxY_smooth = splev(equinoxX_new, splrep(equinoxX, equinoxY, k=2))
summerX_new = np.linspace(summerX.min(), summerX.max(),30)
summerY_smooth = splev(summerX_new, splrep(summerX, summerY, k=2))
winterX_new = np.linspace(winterX.min(), winterX.max(),30)
winterY_smooth = splev(winterX_new, splrep(winterX, winterY, k=2))
将这些用于评论中的数据集,
equinoxAzi = np.array([90, 180, 270])
equinoxAlt = np.array([0, 80, 0])
summerAzi = np.array([180-121.5, 180, 180+121.5])
summerAlt = np.array([0, 60, 0])
winterAzi = np.array([180-58.46, 180, 180+58.46])
winterAlt = np.array([0, 40, 0])
结果是