예제 #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 plot_kite(ax, beta, phi, psi=np.pi):
    y, z = calc_proj(beta, phi)
    psi_proj = corrected_orientation_angle(beta, phi, psi)[2]
    t = MarkerStyle(marker=7)
    t._transform = t.get_transform().rotate_deg(psi_proj * 180. / np.pi)
    marker_obj = ax.plot(y,
                         z,
                         's',
                         marker=t,
                         ms=20,
                         mfc='None',
                         mew=2,
                         mec='k')[0]
예제 #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["markersize"] = markersize
    style["zorder"] = line.get_zorder()
    return style
예제 #6
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
예제 #7
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]
예제 #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_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
예제 #10
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
예제 #11
0
def plot_arrow(longs,
               lats,
               distance,
               min_distance=0.0001,
               dotted=False,
               arrow_colour='k',
               dot_colour='k',
               lw=1):

    if dotted: plt.plot(longs, lats, '--', c=arrow_colour, lw=lw)
    else: plt.plot(longs, lats, c=arrow_colour, lw=lw)

    #plt.plot(longs[1],lats[1],'.',c=dot_colour,ms=10)

    if not dotted and distance > min_distance:

        angle = -np.arctan2(longs[1] - longs[0], lats[1] - lats[0]) * 180 / (
            np.pi)
        t = MarkerStyle(marker='^')
        t._transform = t.get_transform().rotate_deg(angle)
        plt.scatter(np.mean(longs),
                    np.mean(lats),
                    color=arrow_colour,
                    marker=t)  #(3, 0, angle))
예제 #12
0
def quiver_dict(ax,
                dat,
                s=75,
                X=None,
                Y=None,
                inx=True,
                scale=1.0,
                width=None):
    hang = fabric_to_ver_rot(dat['fabric 1'], dat['fabric 2'], dat['fabric 5'])
    if inx:
        ang = fabric_to_ver_rot(dat['fabric 1'], dat['fabric 2'],
                                dat['fabric 3'])
        ang[ang < -45] = ang[ang < -45] + 90.
        ang[ang > 45] = ang[ang > 45] - 90.
        u = np.sin(ang / 180.0 * np.pi) * dat['eigenv 3']
        v = np.cos(ang / 180.0 * np.pi) * dat['eigenv 3']
        units = 'width'
    else:
        u = np.zeros_like(dat['eigenv 3'])
        v = np.ones_like(dat['eigenv 3'])
        units = 'height'
        ang = np.zeros_like(dat['fabric 1'])

    singlemax = dumb_woodcock(dat)
    vertical = dat['fabric 2'] > (1.0 - dat['fabric 2'] - dat['fabric 1'])
    vertical_sm = np.logical_and(vertical, singlemax)
    hor_sm = np.logical_and(~vertical, singlemax)
    quiv = ax.quiver(X.flatten()[vertical_sm],
                     Y.flatten()[vertical_sm],
                     u[vertical_sm],
                     v[vertical_sm],
                     units=units,
                     scale=scale,
                     width=width)
    if np.any(hor_sm):
        hq = [
            ax.plot(X.flatten()[hor_sm],
                    Y.flatten()[hor_sm],
                    marker='.',
                    markersize=2,
                    linestyle='none',
                    color='0.4',
                    label='Single max. partly into page')
        ]
    else:
        hq = []

    planlabel = False
    ooplabel = False
    other_pts = []
    for i in range(np.sum(~singlemax)):
        t = MarkerStyle(marker=HOOP)
        t._transform = t.get_transform().rotate_deg(-ang[~singlemax][i])
        if np.isnan(dat['fabric 1'].flatten()[~singlemax][i]):
            continue
        if np.abs(hang.flatten()[~singlemax][i]) > 1:
            color = '0.4'
            if not ooplabel:
                label = 'Vert. girdle, normal out of x-z'
                ooplabel = True
            else:
                label = None
        else:
            color = 'k'
            if not planlabel:
                label = 'Vert. girdle, normal in x-z'
                planlabel = True
            else:
                label = None

        other_pts.append(
            ax.scatter(X.flatten()[~singlemax][i],
                       Y.flatten()[~singlemax][i],
                       marker=t,
                       s=s,
                       linewidth=0.5,
                       c='none',
                       edgecolors=color,
                       label=label))
    return [quiv] + hq + other_pts