def addItem(self, x, y, shape, color, fill, overlay, z, linestyle, linewidth, linebgcolor): if (linebgcolor is not None and shape not in ('rectangle', 'polygon', 'polylines')): _logger.warning( 'linebgcolor not implemented for %s with matplotlib backend', shape) xView = numpy.array(x, copy=False) yView = numpy.array(y, copy=False) linestyle = normalize_linestyle(linestyle) if shape == "line": item = self.ax.plot(x, y, color=color, linestyle=linestyle, linewidth=linewidth, marker=None)[0] elif shape == "hline": if hasattr(y, "__len__"): y = y[-1] item = self.ax.axhline(y, color=color, linestyle=linestyle, linewidth=linewidth) elif shape == "vline": if hasattr(x, "__len__"): x = x[-1] item = self.ax.axvline(x, color=color, linestyle=linestyle, linewidth=linewidth) elif shape == 'rectangle': xMin = numpy.nanmin(xView) xMax = numpy.nanmax(xView) yMin = numpy.nanmin(yView) yMax = numpy.nanmax(yView) w = xMax - xMin h = yMax - yMin item = Rectangle(xy=(xMin, yMin), width=w, height=h, fill=False, color=color, linestyle=linestyle, linewidth=linewidth) if fill: item.set_hatch('.') if linestyle != "solid" and linebgcolor is not None: item = _DoubleColoredLinePatch(item) item.linebgcolor = linebgcolor self.ax.add_patch(item) elif shape in ('polygon', 'polylines'): points = numpy.array((xView, yView)).T if shape == 'polygon': closed = True else: # shape == 'polylines' closed = numpy.all(numpy.equal(points[0], points[-1])) item = Polygon(points, closed=closed, fill=False, color=color, linestyle=linestyle, linewidth=linewidth) if fill and shape == 'polygon': item.set_hatch('/') if linestyle != "solid" and linebgcolor is not None: item = _DoubleColoredLinePatch(item) item.linebgcolor = linebgcolor self.ax.add_patch(item) else: raise NotImplementedError("Unsupported item shape %s" % shape) item.set_zorder(z + 1) item.set_animated(True) return item
def addItem(self, x, y, legend, shape, color, fill, overlay, z, linestyle, linewidth, linebgcolor): if (linebgcolor is not None and shape not in ('rectangle', 'polygon', 'polylines')): _logger.warning( 'linebgcolor not implemented for %s with matplotlib backend', shape) xView = numpy.array(x, copy=False) yView = numpy.array(y, copy=False) linestyle = normalize_linestyle(linestyle) if shape == "line": item = self.ax.plot(x, y, label=legend, color=color, linestyle=linestyle, linewidth=linewidth, marker=None)[0] elif shape == "hline": if hasattr(y, "__len__"): y = y[-1] item = self.ax.axhline(y, label=legend, color=color, linestyle=linestyle, linewidth=linewidth) elif shape == "vline": if hasattr(x, "__len__"): x = x[-1] item = self.ax.axvline(x, label=legend, color=color, linestyle=linestyle, linewidth=linewidth) elif shape == 'rectangle': xMin = numpy.nanmin(xView) xMax = numpy.nanmax(xView) yMin = numpy.nanmin(yView) yMax = numpy.nanmax(yView) w = xMax - xMin h = yMax - yMin item = Rectangle(xy=(xMin, yMin), width=w, height=h, fill=False, color=color, linestyle=linestyle, linewidth=linewidth) if fill: item.set_hatch('.') if linestyle != "solid" and linebgcolor is not None: item = _DoubleColoredLinePatch(item) item.linebgcolor = linebgcolor self.ax.add_patch(item) elif shape in ('polygon', 'polylines'): points = numpy.array((xView, yView)).T if shape == 'polygon': closed = True else: # shape == 'polylines' closed = numpy.all(numpy.equal(points[0], points[-1])) item = Polygon(points, closed=closed, fill=False, label=legend, color=color, linestyle=linestyle, linewidth=linewidth) if fill and shape == 'polygon': item.set_hatch('/') if linestyle != "solid" and linebgcolor is not None: item = _DoubleColoredLinePatch(item) item.linebgcolor = linebgcolor self.ax.add_patch(item) else: raise NotImplementedError("Unsupported item shape %s" % shape) item.set_zorder(z) if overlay: item.set_animated(True) self._overlays.add(item) return item