2014-09-04 125 views
1

我想用matplotlib繪製極座標圖,並且想要執行以下操作:a)用科學記數法顯示刻度標記 b)以指定的時間間隔顯示半徑圓。matplotlib極座標圖科學記數法

誰能給我如何做一個建議)和b)低於

import numpy as np 
import matplotlib.pyplot as plt 

fig = plt.figure() 
ax = fig.add_subplot(111, polar=True) 

theta =[np.pi/3, np.pi/3] 
theta2 =[np.pi/6, np.pi/6] 

r = [0.0, 8.0e-04] 
r2 = [0.0, 7.0e-04] 
ax.plot(theta, r, 'r-', label ='Observed') 
ax.plot(theta2, r2, 'b-', label ='Simulated') 

ax.grid(True) 

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.25), 
      ncol=3, fancybox=True, shadow=True) 
plt.show() 
+0

你的'legend'調用不工作,因爲'ncol'。 – Adobe 2014-09-05 05:05:21

+0

@Adobe你是對的傳說調用並不完全正確,但是當我嘗試它時,傳說實際上存在,但它在可見圖形之外,如果將圖形調整爲小圖形,則開始看到它。 – Ajean 2014-09-05 15:28:25

回答

3

守則指定徑向刻度的位置,這是非常簡單 - 只需將rticks:

ax.set_rticks([0.0002, 0.0004, 0.0006, 0.0008]) 

格式有幾個選項,它取決於你想如何顯示刻度。默認的格式化程序會自動切換到大數和小數的科學。如果你想改變它的閾值它認爲是「小」,你可以做到這一點通過修改y軸格式化(y軸的徑向軸):

ax.yaxis.get_major_formatter().set_powerlimits((-3,4)) # Things smaller than 1e-3 
                 # will be in scientific 
                 # notation 

然而,這看起來有點滑稽我,它將小的「1e-4」放在情節的左上角。

所以,如果你想強制當前的徑向滴答是科學記數法,他們是一種方法是使用自己的格式。以下用途FormatStrFormatter

import matplotlib.ticker as ticker 
# plotting code here 
frmtr = ticker.FormatStrFormatter('%4.1e') 
ax.yaxis.set_major_formatter(frmtr) 

有大量的可供選擇通過matplotlib.ticker如果不這樣做你想要什麼。第二個格式選項給我這個: outputplot