예제 #1
0
파일: gaplot.py 프로젝트: Jravis/gaepsi
    def scatter(self, x, y, s, ax=None, fancy=False, **kwargs):
        """ takes data coordinate x, y and plot them to a data coordinate axes,
        s is the radius in data units. 
        When fancy is True, apply a radient filter so that the 
        edge is blent into the background; better with marker='o' or marker='+'. """
        X, Y, S = numpy.asarray([x, y, s])
        if ax is None: ax = self.default_axes

        def filter(image, dpi):
            # this is problematic if the marker is clipped.
            if image.shape[0] <= 1 and image.shape[1] <= 1: return image
            xgrad = 1.0 \
               - numpy.fabs(numpy.linspace(0, 2,
                  image.shape[0], endpoint=True) - 1.0)
            ygrad = 1.0 \
               - numpy.fabs(numpy.linspace(0, 2,
                  image.shape[1], endpoint=True) - 1.0)
            image[..., 3] *= xgrad[:, None]**0.5
            image[..., 3] *= ygrad[None, :]**0.5
            return image, 0, 0

        marker = kwargs.pop('marker', 'x')
        verts = kwargs.pop('verts', None)
        # to be API compatible
        if marker is None and not (verts is None):
            marker = (verts, 0)
            verts = None

        objs = []
        color = kwargs.pop('color', None)
        edgecolor = kwargs.pop('edgecolor', None)
        linewidth = kwargs.pop('linewidth', kwargs.pop('lw', None))

        marker_obj = MarkerStyle(marker)
        if not marker_obj.is_filled():
            edgecolor = color

        for x, y, r in numpy.nditer([X, Y, S], flags=['zerosize_ok']):
            path = marker_obj.get_path().transformed(
                marker_obj.get_transform().scale(r).translate(x, y))
            obj = PathPatch(
                path,
                facecolor=color,
                edgecolor=edgecolor,
                linewidth=linewidth,
                transform=ax.transData,
            )
            obj.set_alpha(1.0)
            if fancy:
                obj.set_agg_filter(filter)
                obj.rasterized = True
            objs += [obj]
            ax.add_artist(obj)
        ax.autoscale_view()

        return objs
예제 #2
0
  def scatter(self, x, y, s, ax=None, fancy=False, **kwargs):
    """ takes data coordinate x, y and plot them to a data coordinate axes,
        s is the radius in data units. 
        When fancy is True, apply a radient filter so that the 
        edge is blent into the background; better with marker='o' or marker='+'. """
    X, Y, S = numpy.asarray([x, y, s])
    if ax is None: ax=self.default_axes
    
    def filter(image, dpi):
      # this is problematic if the marker is clipped.
      if image.shape[0] <=1 and image.shape[1] <=1: return image
      xgrad = 1.0 \
         - numpy.fabs(numpy.linspace(0, 2, 
            image.shape[0], endpoint=True) - 1.0)
      ygrad = 1.0 \
         - numpy.fabs(numpy.linspace(0, 2, 
            image.shape[1], endpoint=True) - 1.0)
      image[..., 3] *= xgrad[:, None] ** 0.5
      image[..., 3] *= ygrad[None, :] ** 0.5
      return image, 0, 0

    marker = kwargs.pop('marker', 'x')
    verts = kwargs.pop('verts', None)
    # to be API compatible
    if marker is None and not (verts is None):
        marker = (verts, 0)
        verts = None

    objs = []
    color = kwargs.pop('color', None)
    edgecolor = kwargs.pop('edgecolor', None)
    linewidth = kwargs.pop('linewidth', kwargs.pop('lw', None))

    marker_obj = MarkerStyle(marker)
    if not marker_obj.is_filled():
        edgecolor = color

    for x,y,r in numpy.nditer([X, Y, S], flags=['zerosize_ok']):
      path = marker_obj.get_path().transformed(
         marker_obj.get_transform().scale(r).translate(x, y))
      obj = PathPatch(
                path,
                facecolor = color,
                edgecolor = edgecolor,
                linewidth = linewidth,
                transform = ax.transData,
              )
      obj.set_alpha(1.0)
      if fancy:
        obj.set_agg_filter(filter)
        obj.rasterized = True
      objs += [obj]
      ax.add_artist(obj)
    ax.autoscale_view()

    return objs
예제 #3
0
    def _html_args(self):
        transform = self.line.get_transform() - self.ax.transData
        data = transform.transform(self.line.get_xydata()).tolist()

        markerstyle = MarkerStyle(self.line.get_marker())
        markersize = self.line.get_markersize()
        markerpath = path_data(markerstyle.get_path(),
                               (markerstyle.get_transform()
                                + Affine2D().scale(markersize, -markersize)))

        return dict(lineid=self.lineid,
                    data=json.dumps(data),
                    markerpath=json.dumps(markerpath))
예제 #4
0
def get_marker_style(line):
    """Get the style dictionary for matplotlib marker objects"""
    style = {}
    style["alpha"] = line.get_alpha()
    if style["alpha"] is None:
        style["alpha"] = 1

    style["facecolor"] = color_to_hex(line.get_markerfacecolor())
    style["edgecolor"] = color_to_hex(line.get_markeredgecolor())
    style["edgewidth"] = line.get_markeredgewidth()

    style["marker"] = line.get_marker()
    markerstyle = MarkerStyle(line.get_marker())
    markersize = line.get_markersize()
    markertransform = markerstyle.get_transform() + Affine2D().scale(markersize, -markersize)
    style["markerpath"] = SVG_path(markerstyle.get_path(), markertransform)
    style["markersize"] = markersize
    style["zorder"] = line.get_zorder()
    return style
예제 #5
0
def get_marker_style(line):
    """Get the style dictionary for matplotlib marker objects"""
    style = {}
    style['alpha'] = line.get_alpha()
    if style['alpha'] is None:
        style['alpha'] = 1

    style['facecolor'] = color_to_hex(line.get_markerfacecolor())
    style['edgecolor'] = color_to_hex(line.get_markeredgecolor())
    style['edgewidth'] = line.get_markeredgewidth()

    style['marker'] = line.get_marker()
    markerstyle = MarkerStyle(line.get_marker())
    markersize = line.get_markersize()
    markertransform = (markerstyle.get_transform() +
                       Affine2D().scale(markersize, -markersize))
    style['markerpath'] = SVG_path(markerstyle.get_path(), markertransform)
    style['zorder'] = line.get_zorder()
    return style
예제 #6
0
    def get_patches(self, ax):
        ranges = LineCollection(self._cap_ranges, linestyle="solid")
        links = LineCollection(self._oob_links,
                               linestyle="dotted",
                               colors=colorConverter.to_rgba_array("#808080"))

        color = colorConverter.to_rgba_array("#DC143C")
        scales = np.array((20, ))
        marker_obj = MarkerStyle("o")
        path = marker_obj.get_path().transformed(marker_obj.get_transform())

        offsets = PathCollection((path, ),
                                 scales,
                                 facecolors=color,
                                 offsets=self._oob_offsets,
                                 transOffset=ax.transData)
        offsets.set_transform(IdentityTransform())

        return [ranges, links, offsets]
예제 #7
0
def get_marker_style(line):
    """Get the style dictionary for matplotlib marker objects"""
    style = {}
    style["alpha"] = line.get_alpha()
    if style["alpha"] is None:
        style["alpha"] = 1

    style["facecolor"] = export_color(line.get_markerfacecolor())
    style["edgecolor"] = export_color(line.get_markeredgecolor())
    style["edgewidth"] = line.get_markeredgewidth()

    style["marker"] = line.get_marker()
    markerstyle = MarkerStyle(line.get_marker())
    markersize = line.get_markersize()
    markertransform = markerstyle.get_transform() + Affine2D().scale(
        markersize, -markersize)
    style["markerpath"] = SVG_path(markerstyle.get_path(), markertransform)
    style["markersize"] = markersize
    style["zorder"] = line.get_zorder()
    return style
예제 #8
0
def get_marker_style(line):
    """Get the style dictionary for matplotlib marker objects"""
    style = {}
    style['alpha'] = line.get_alpha()
    if style['alpha'] is None:
        style['alpha'] = 1

    style['facecolor'] = export_color(line.get_markerfacecolor())
    style['edgecolor'] = export_color(line.get_markeredgecolor())
    style['edgewidth'] = line.get_markeredgewidth()

    style['marker'] = line.get_marker()
    markerstyle = MarkerStyle(line.get_marker())
    markersize = line.get_markersize()
    markertransform = (markerstyle.get_transform()
                       + Affine2D().scale(markersize, -markersize))
    style['markerpath'] = SVG_path(markerstyle.get_path(),
                                   markertransform)
    style['markersize'] = markersize
    style['zorder'] = line.get_zorder()
    return style
예제 #9
0
def get_line_style(line):
    """Get the style dictionary for matplotlib Line2D objects."""
    style = {}
    style['alpha'] = line.get_alpha()
    if style['alpha'] is None:
        style['alpha'] = 1
    style['color'] = color_to_hex(line.get_color())
    style['linewidth'] = line.get_linewidth()
    style['dasharray'] = get_dasharray(line)
    style['facecolor'] = color_to_hex(line.get_markerfacecolor())
    style['edgecolor'] = color_to_hex(line.get_markeredgecolor())
    style['edgewidth'] = line.get_markeredgewidth()
    style['marker'] = line.get_marker()
    markerstyle = MarkerStyle(line.get_marker())
    markersize = line.get_markersize()
    markertransform = (markerstyle.get_transform()
                       + Affine2D().scale(markersize, -markersize))
    style['markerpath'] = SVG_path(markerstyle.get_path(), markertransform)
    style['markersize'] = markersize
    style['zorder'] = line.get_zorder()
    return style