【问题标题】:Stereographic Sun Diagram matplotlib polar plot python立体太阳图 matplotlib 极坐标图 python
【发布时间】:2017-04-15 07:25:55
【问题描述】:

我正在尝试创建一个类似于以下的简单立体太阳路径图: 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()

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

非常感谢任何帮助。

【问题讨论】:

  • 简短的回答是您需要立体投影而不是极坐标投影。但是,这意味着您要么必须 a) 自己对 Axes 进行子类化(查看 matplotlib 中的 projections.geo_axes,或者 b)调整现有代码以执行您想要的操作。 (只是为了插入我自己的东西,mplstereonet:github.com/joferkington/mplstereonet 可以适应这个,但它是用于地质数据的。)我接下来一两天很忙,但我会尝试发布两者的例子如果有人不打败我。 :)
  • 经过大量互联网搜索后,我认为使用 y_scale 可能就足够了:ScaleBase Example。虽然我不确定反向比例是否会起作用。会及时通知您。
  • @tcaswell 你好,请看下面的答案。

标签: python matplotlib polar-coordinates


【解决方案1】:

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

以下是我为 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')

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

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 2014-03-13
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多