对于子图(self.intensity
),我想要阴影图下的区域。
我试过这个,希望它是正确的语法:
self.intensity.fill_between(arange(l,r), 0, projection)
我打算在projection
整数限制内对(l,r)
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 :(得分:3)
看起来你正试图填充从l到r的投影部分。 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()