2012-10-12 97 views
4

我想創建一個類似這些簡單的立體太陽路徑圖: http://wiki.naturalfrequency.com/wiki/Sun-Path_Diagram赤孫圖matplotlib極座標圖蟒蛇

我能夠旋轉極座標圖和比例設置爲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

簡短的回答是,你想有一個立體投影,而不是極投影。然而,這意味着你要麼必須自己創建'Axes'的子類(看一下matplotlib中的'projections.geo_axes',或者b)修改現有的代碼來做你想做的事情。 (只是爲了插入我自己的東西,mplstereonet:https://github.com/joferkington/mplstereonet可以適應這一點,但它是用於地質數據。)我在第二天或第二天忙着工作,如果有人沒有把我打倒,我會試着發佈一個例子。 :) –

+0

經過大量的網絡搜索,我認爲玩y_scale可能就足夠了:[ScaleBase Example](http://matplotlib.org/examples/api/custom_scale_example.html)。雖然我不確定反向標度是否可行。會及時向大家發佈。 – ivvv

+0

這方面的進展如何? – tacaswell

回答

6

我終於有時間玩matplotlib。經過大量搜索後,Joe Kington指出的正確方法是對Axes進行子類化。我發現了使用優秀的底圖模塊更快的方法。

下面是一些我已經適用於stackoverflow的代碼。太陽高度和方位角用Pysolar計算,並在熊貓中創建一組時間戳。

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點。

stereographic plot, note I have plotted Winter/Summer Solstice and Autumn Equinox