如何在sunpath图上绘制每个点的小时数?

时间:2016-04-03 22:55:33

标签: python python-2.7 matplotlib-basemap

以下是绘制太阳图图的代码。我的问题是,您将使用什么函数来为图表上绘制的每个点注释小时数。我已经尝试过matplotlib中的plt.annotate和plt.text,但它似乎不起作用,因为绘图是使用底图完成的。

Stereographic Sun Diagram matplotlib polar plot python

1 个答案:

答案 0 :(得分:0)

以下是尝试使用您链接到的问题中的代码和annotate方法:

import matplotlib.pylab as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

winterAzi = [90,180,270]
winterAlt = np.array([0,42,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
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')


# plot the winter values
myMap.plot(winterX,winterY ,'bo')

# Annotate points
for x,y,label in zip(winterAlt, winterAzi, ["point 1","point 2","point 3"]):
    plt.annotate(label, xy=myMap(y, -x), xycoords="data", xytext=(5, 5), 
                 textcoords='offset points',ha="left",va="center",fontsize=12) 

末尾的循环遍历每个点的x / y坐标和标签,并使用annotate在指定坐标处添加标签(xytext中给出的偏移量)

输出:

标题

output