2012-06-14 101 views
1

對於子圖(self.intensity),我想遮蔽圖下的區域。在matplotlib中的曲線下繪圖

我想這一點,希望這是正確的語法:

self.intensity.fill_between(arange(l,r), 0, projection) 

我打算以用於內(l,r)整數限制projection numpy的陣列做陰影。

但它給了我一個錯誤。我如何正確地做到這一點?


繼承人的回溯:

Traceback (most recent call last): 
    File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_wx.py", line 1289, in _onLeftButtonDown 
    FigureCanvasBase.button_press_event(self, x, y, 1, guiEvent=evt) 
    File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1576, in button_press_event 
    self.callbacks.process(s, mouseevent) 
    File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 265, in process 
    proxy(*args, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 191, in __call__ 
    return mtd(*args, **kwargs) 
    File "/root/dev/spectrum/spectrum/plot_handler.py", line 55, in _onclick 
    self._call_click_callback(event.xdata) 
    File "/root/dev/spectrum/spectrum/plot_handler.py", line 66, in _call_click_callback 
    self.__click_callback(data) 
    File "/root/dev/spectrum/spectrum/plot_handler.py", line 186, in _on_plot_click 
    band_data = self._band_data) 
    File "/root/dev/spectrum/spectrum/plot_handler.py", line 95, in draw 
    self.intensity.fill_between(arange(l,r), 0, projection) 
    File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6457, in fill_between 
    raise ValueError("Argument dimensions are incompatible") 
ValueError: Argument dimensions are incompatible 
+0

我們將需要比這更多的信息。 'l','r'和'projection'是什麼?回溯告訴你'arange(l,r)'與'projection'的長度不一樣。你是否想在'arange'生成的序列中包含'r'的值,即'arange(l,r + 1)'? – Chris

+0

編輯我的問題。我希望它包含所有相關信息?它將'scipy.arange'導入到全局名稱空間中。我打算'arange'產生'投影'的極限 – aitchnyu

回答

3

好像你正試圖填補投影從左至右的一部分。 fill_between期望x和y數組的長度相等,所以你不能指望只填充部分曲線。

爲了得到你想要的,你可以執行以下任一操作: 1.只發送需要填充的部分投影到命令;並分別繪製剩餘的投影。 2.發送一個單獨的布爾數組作爲參數,該參數定義要填寫的部分。請參閱documentation

對於前一種方法,請參見下面的示例代碼:

from pylab import * 

a = subplot(111) 

t = arange(1, 100)/50. 
projection = sin(2*pi*t) 

# Draw the original curve 
a.plot(t, projection) 
# Define areas to fill in 
l, r = 10, 50 
# Fill the areas 
a.fill_between(t[l:r], projection[l:r]) 
show() 
+0

太棒了!使用'projection [l:r]'固定它! – aitchnyu