立体太阳图 matplotlib 极坐标图 python [英] Stereographic Sun Diagram matplotlib polar plot python

查看:89
本文介绍了立体太阳图 matplotlib 极坐标图 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建类似于以下内容的简单立体太阳路径图: http://wiki.naturalfrequency.com/wiki/Sun-Path_Diagram

I am trying to create a simple stereographic sun path diagram similar to these: http://wiki.naturalfrequency.com/wiki/Sun-Path_Diagram

我可以旋转极坐标图并将比例设置为 90.如何反转 y 轴?当前轴从 0>90 开始,如何将轴反转到 90>0 以表示方位角?

I am able to rotate a polar plot and set the scale to 90. How do I go about reversing the y-axis? Currently the axis goes from 0>90, how do I reverse the axis to 90>0 to represent the azimuth?

我尝试过:

ax.invert_yaxis()
ax.yaxis_inverted()

进一步,我将如何创建立体投影而不是等距投影?

Further, how would I go about creating a stereographic projection as opposed to a equidistant?

我的代码:

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

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

Currently my code doesn't seem to even plot the lines correctly, do I need need to convert the angle or degrees into something else?

非常感谢任何帮助.

推荐答案

我终于有时间玩弄 matplotlib.经过大量搜索,Joe Kington 指出的正确方法是对 Axes 进行子类化.我发现了使用出色的底图模块的更快方法.

I finally had time to play around with matplotlib. After much searching, the correct way as Joe Kington points out is to subclass the Axes. I found a much quicker way utilising the excellent basemap module.

以下是我为 stackoverflow 改编的一些代码.太阳高度和方位角是使用Pysolar以及在熊猫中创建的一组时间序列戳计算出来的.

Below is some code I have adapted for stackoverflow. The sun altitude and azimuth were calculated with Pysolar with a set of timeseries stamps created in 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')

请注意,目前我只是在绘制点,您必须确保线点在日出/日落时在 alt 0 处有一个点.

Note that currently I am only plotting points, you will have to make sure that line points have a point at alt 0 at sunrise/sunset.

这篇关于立体太阳图 matplotlib 极坐标图 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆