立体太阳图:使用matplotlib绘制python极坐标图

5
我将尝试创建一个类似于这些的简单立体投影太阳路径图: http://wiki.naturalfrequency.com/wiki/Sun-Path_Diagram 我已经能够旋转极坐标图并将比例设置为90。如何反转y轴? 目前轴从0>90,如何将轴反转为90>0以表示方位角?
我已经尝试过:
ax.invert_yaxis()
ax.yaxis_inverted()

此外,我将如何创建一个立体投影而不是等距投影呢?

我的代码:

import matplotlib.pylab as plt
testFig = plt.figure(1, figsize=(8,8))
rect = [0.1,0.1,0.8,0.8]
testAx = testFig.add_axes(rect,polar=True)
testAx.invert_yaxis()
testAx.set_theta_zero_location('N')
testAx.set_theta_direction(-1)

Azi = [90,180,270]
Alt= [0,42,0]
testAx.plot(Azi,Alt)
plt.show()

目前我的代码似乎无法正确绘制线条,我需要将角度或度数转换为其他内容吗?

非常感谢任何帮助。


1
简短回答是您需要一个立体投影而不是极坐标投影。然而,这意味着您要么a)自己子类化Axes(请查看matplotlib中的projections.geo_axes),或者b)调整现有代码以符合您的需求。(顺便推荐一下我的mplstereonet:https://github.com/joferkington/mplstereonet,可以适应这种情况,但它是为地质数据设计的)我接下来的一两天很忙,如果没有其他人比我更快,我会尝试发布两个示例 :) - Joe Kington
经过大量的互联网搜索,我认为玩弄y_scale可能足够:ScaleBase Example。虽然我不确定反向刻度是否有效。我会让你知道的。 - ivvv
@tcaswell 你好,请查看下面的答案。 - ivvv
1个回答

8

我最近有时间尝试使用matplotlib。经过大量搜索,正如Joe Kington指出的那样,正确的方法是继承Axes。我发现一个更快的方法,利用了优秀的basemap模块。

下面是一些我为stackoverflow修改的代码。太阳高度和方位角是使用Pysolar计算的,时间戳集合是在pandas中创建的。

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

winterAzi = datafomPySolarAzi
winterAlt = datafromPySolarAlt

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

请注意,目前我只绘制点,您需要确保线点在日出/日落时有一个高度为0的点。
请注意,我已经绘制了冬至/夏至和秋分的立体投影图。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接