如何通过两个点(直径末端)画一个圆圈?

时间:2017-04-26 18:58:13

标签: python matplotlib plot matplotlib-basemap

立体投影有两点,如图所示:

enter image description here

这些点应该位于圆的一角形的终点上。如何绘制一个通过这两点的圆圈?

上述情节的代码:

import matplotlib.pylab as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
from scipy.interpolate import splev, splrep

# 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')


# 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')

summerAzi = np.array([0, 360])
summerAlt = np.array([40, 4])
summerX, summerY = myMap(summerAzi, -summerAlt)


summerX_new = np.linspace(summerX.min(), summerX.max(),30)
summerY_smooth = splev(summerX_new, splrep(summerX, summerY, k=1))

myMap.plot(summerX_new, summerY_smooth, 'g')

myMap.plot(summerX, summerY, 'go')   
plt.show()

2 个答案:

答案 0 :(得分:1)

此极坐标表示中的圆圈看起来不像矩形网格上的圆圈(即"圆形#34;)。除此之外,您可以像在笛卡尔平面上一样绘制圆,从极坐标开始,转换为笛卡尔坐标,偏移中心并使用绘图函数。

summerAzi = np.array([0, 360])
summerAlt = -np.array([40, 4])
summerX, summerY = myMap(summerAzi, summerAlt)

phi = np.linspace(0,2.*np.pi)
r = np.abs(np.diff(summerAlt))/2.
x = r*np.cos(phi)
y = -r*np.sin(phi)+summerAlt.mean()
X,Y= myMap(x,y)

myMap.plot(X,Y, color="crimson")
myMap.plot(summerX, summerY, color="gold", marker="o")

enter image description here

答案 1 :(得分:1)

内置的tissot()函数足以在共形投影上绘制圆圈(如本例所示)。在非共形投影上,它绘制椭圆。 这里,Tissot indicatrix的中点是(0,-22)度。 它的半径=(40-4)/ 2 = 18度。 分数= 36很好。

相关代码是:

myMap.tissot(0, -22, 18, 36, \
             facecolor='none', \
             edgecolor='#ff0000', \
             linewidth=1, \
             alpha=1)

enter image description here