Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何制作只有3个已知点的连续抛物线弧?_Python_Matplotlib_Plot_Scipy - Fatal编程技术网

Python 如何制作只有3个已知点的连续抛物线弧?

Python 如何制作只有3个已知点的连续抛物线弧?,python,matplotlib,plot,scipy,Python,Matplotlib,Plot,Scipy,我正在尝试绘制一个类似 我得到的是: 代码如下: 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

我正在尝试绘制一个类似

我得到的是:

代码如下:

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()

我试图通过三个点(以蓝色、绿色和红色显示)绘制出连接所有相同颜色的圆弧。如何制作像第一张图片中那样的圆弧?

通过
k
点创建度数的样条线不一定是个好主意。那里什么事都可能发生

由于
scipy.interpolate.spline
无论如何都会贬值,因此可以使用
scipy.interpolate.splev
scipy.interpolate.splep
并将样条曲线限制为阶数
k=2
。(尝试使用
k=3
将导致错误,预计会得到3分)

使用这些注释中的数据集

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])
结果是


请您解释一下您的第一句话,为什么不应该使用k到k点的学位?好的,这可能会扩大这个问题的范围。可以通过k个点创建deg k的样条曲线;然而,这需要在边界上附加条件。Scipy使用的B样条曲线没有此附加条件。所以在这里我们可以简单地接受Wikipedia在B样条曲线文章中所说的:样条曲线函数是一个分段多项式函数,它不处理这些数据:
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])
对于某些数据集,它也给出了错误:
ValueError:error on input data
“Scipy使用的B样条曲线没有这个额外条件”--最近足够多的scipy提供了
CubicSpline
,它接受几种类型的边界条件。从0.19.0开始,还有
make_interp_spline
,可用于抛物线。一个很好的答案,+1。
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])