2017-05-02 43 views
3

我想繪製一整年的matplotlib中的極座標圖數據,並且無法定位任何這樣的例子。我設法根據this thread轉換大熊貓的日期,但我無法將我的頭圍繞(litterally)y軸或theta。matplolib年度數據極地圖

這是我迄今爲止得到:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
import pandas as pd 

times = pd.date_range("01/01/2016", "12/31/2016") 
rand_nums = np.random.rand(len(times),1) 
df = pd.DataFrame(index=times, data=rand_nums, columns=['A']) 

ax = plt.subplot(projection='polar') 
ax.set_theta_direction(-1) 
ax.set_theta_zero_location("N") 
ax.plot(mdates.date2num(df.index.to_pydatetime()), df['A']) 
plt.show() 

這給了我this plot

縮小日期範圍,瞭解什麼是對
times = pd.date_range("01/01/2016", "01/05/2016")去我得到this plot

我收集的是,該系列的開始時間在90到135之間,但我怎麼「重新映射」這個,以便我的年份日期範圍從北方起點開始並結束?

回答

3

極座標圖的角度範圍在輻射源的整個圓周範圍內,即[0, 2π]。 因此,需要將日期範圍標準化爲整個圓。

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
import pandas as pd 

times = pd.date_range("01/01/2016", "12/31/2016") 
rand_nums = np.random.rand(len(times),1) 
df = pd.DataFrame(index=times, data=rand_nums, columns=['A']) 

ax = plt.subplot(projection='polar') 
ax.set_theta_direction(-1) 
ax.set_theta_zero_location("N") 

t = mdates.date2num(df.index.to_pydatetime()) 
y = df['A'] 
tnorm = (t-t.min())/(t.max()-t.min())*2.*np.pi 
ax.fill_between(tnorm,y ,0, alpha=0.4) 
ax.plot(tnorm,y , linewidth=0.8) 
plt.show() 

enter image description here

+0

驚人的,謝謝! –

+0

我以前做過,但它說我沒有足夠的業力來數!我似乎已經贏得了一些。也許我可以在我的下一個問題中使用圖像。 –