1

对于子图 ( self.intensity),我想在图形下方遮蔽区域。

我试过这个,希望它是正确的语法:

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

我打算在整数范围projection内对 numpy 数组进行着色。(l,r)

但这给了我一个错误。我该如何正确地做到这一点?


这是追溯:

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
4

1 回答 1

3

似乎您正在尝试填充从 l 到 r 的投影部分。fill_between 期望 x 和 y 数组长度相等,因此您不能期望仅填充曲线的一部分。

要得到你想要的,你可以执行以下任一操作: 1. 只将需要填充的部分投影发送到命令;并分别绘制其余的投影。2.发送一个单独的布尔数组作为定义要填写的部分的参数。请参阅文档

对于前一种方法,请参见下面的示例代码:

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()
于 2012-06-14T12:13:29.350 回答