当前位置: 首页>>代码示例>>Python>>正文


Python offsetbox.DrawingArea类代码示例

本文整理汇总了Python中matplotlib.offsetbox.DrawingArea的典型用法代码示例。如果您正苦于以下问题:Python DrawingArea类的具体用法?Python DrawingArea怎么用?Python DrawingArea使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DrawingArea类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_offsetbox_clipping

def test_offsetbox_clipping():
    # - create a plot
    # - put an AnchoredOffsetbox with a child DrawingArea
    #   at the center of the axes
    # - give the DrawingArea a gray background
    # - put a black line across the bounds of the DrawingArea
    # - see that the black line is clipped to the edges of
    #   the DrawingArea.
    fig, ax = plt.subplots()
    size = 100
    da = DrawingArea(size, size, clip=True)
    bg = mpatches.Rectangle((0, 0), size, size,
                            facecolor='#CCCCCC',
                            edgecolor='None',
                            linewidth=0)
    line = mlines.Line2D([-size*.5, size*1.5], [size/2, size/2],
                         color='black',
                         linewidth=10)
    anchored_box = AnchoredOffsetbox(
        loc=10,
        child=da,
        pad=0.,
        frameon=False,
        bbox_to_anchor=(.5, .5),
        bbox_transform=ax.transAxes,
        borderpad=0.)

    da.add_artist(bg)
    da.add_artist(line)
    ax.add_artist(anchored_box)
    ax.set_xlim((0, 1))
    ax.set_ylim((0, 1))
开发者ID:magnunor,项目名称:matplotlib,代码行数:32,代码来源:test_offsetbox.py

示例2: add_offsetboxes

def add_offsetboxes(ax, size=10, margin=.1, color='black'):
    """
    Surround ax with OffsetBoxes
    """
    m, mp = margin, 1+margin
    anchor_points = [(-m, -m), (-m, .5), (-m, mp),
                     (mp, .5), (.5, mp), (mp, mp),
                     (.5, -m), (mp, -m), (.5, -m)]
    for point in anchor_points:
        da = DrawingArea(size, size)
        background = Rectangle((0, 0), width=size,
                               height=size,
                               facecolor=color,
                               edgecolor='None',
                               linewidth=0,
                               antialiased=False)
        da.add_artist(background)

        anchored_box = AnchoredOffsetbox(
            loc='center',
            child=da,
            pad=0.,
            frameon=False,
            bbox_to_anchor=point,
            bbox_transform=ax.transAxes,
            borderpad=0.)
        ax.add_artist(anchored_box)
    return anchored_box
开发者ID:vapier,项目名称:matplotlib,代码行数:28,代码来源:test_tightlayout.py

示例3: pie

def pie(
    plot,
    p,
    values,
    colors=None,
    size=16,
    norm=True,
    xoff=0,
    yoff=0,
    halign=0.5,
    valign=0.5,
    xycoords="data",
    boxcoords=("offset points"),
):
    """
    Draw a pie chart

    Args:
    plot (Tree): A Tree plot instance
    p (Node): A Node object
    values (list): A list of floats.
    colors (list): A list of strings to pull colors from. Optional.
    size (float): Diameter of the pie chart
    norm (bool): Whether or not to normalize the values so they
      add up to 360
    xoff, yoff (float): X and Y offset. Optional, defaults to 0
    halign, valign (float): Horizontal and vertical alignment within
      box. Optional, defaults to 0.5

    """
    x, y = _xy(plot, p)
    da = DrawingArea(size, size)
    r = size * 0.5
    center = (r, r)
    x0 = 0
    S = 360.0
    if norm:
        S = 360.0 / sum(values)
    if not colors:
        c = _colors.tango()
        colors = [c.next() for v in values]
    for i, v in enumerate(values):
        theta = v * S
        if v:
            da.add_artist(Wedge(center, r, x0, x0 + theta, fc=colors[i], ec="none"))
        x0 += theta
    box = AnnotationBbox(
        da,
        (x, y),
        pad=0,
        frameon=False,
        xybox=(xoff, yoff),
        xycoords=xycoords,
        box_alignment=(halign, valign),
        boxcoords=boxcoords,
    )
    plot.add_artist(box)
    plot.figure.canvas.draw_idle()
    return box
开发者ID:rhr,项目名称:ivy,代码行数:59,代码来源:symbols.py

示例4: make_shape

def make_shape(color, shape, size, alpha, y_offset = 10, height = 20):
    color = color if color != None else "k" # Default value if None
    shape = shape if shape != None else "o"
    size = size*0.6+45 if size != None else 75
    viz = DrawingArea(30, height, 8, 1)
    key = mlines.Line2D([0], [y_offset], marker=shape, markersize=size/12.0,
                        mec=color, c=color, alpha=alpha)
    viz.add_artist(key)
    return viz
开发者ID:9629831527,项目名称:ggplot,代码行数:9,代码来源:legend.py

示例5: make_line_key

def make_line_key(label, color):
    label = str(label)
    idx = len(label)
    pad = 20 - idx
    lab = label[:max(idx, 20)]
    pad = " "*pad
    label = TextArea("  %s" % lab, textprops=dict(color="k"))
    viz = DrawingArea(20, 20, 0, 0)
    viz.add_artist(Rectangle((0, 5), width=16, height=5, fc=color))
    return HPacker(children=[viz, label], height=25, align="center", pad=5, sep=0)
开发者ID:adslyw,项目名称:ggplot,代码行数:10,代码来源:legend.py

示例6: make_line

def make_line(color, style, alpha, width = 20,
              y_offset = 10, height = 20, linewidth = 3):
    color = color if color != None else "k" # Default value if None
    style = style if style != None else "-"
    viz = DrawingArea(30, 10, 0, -5)
    x = np.arange(0.0, width, width/7.0)
    y = np.repeat(y_offset, x.size)
    key = mlines.Line2D(x, y, linestyle=style, linewidth=linewidth,
                        alpha=alpha, c=color)
    viz.add_artist(key)
    return viz
开发者ID:9629831527,项目名称:ggplot,代码行数:11,代码来源:legend.py

示例7: make_marker_key

def make_marker_key(label, marker):
    idx = len(label)
    pad = 20 - idx
    lab = label[:max(idx, 20)]
    pad = " "*pad
    label = TextArea("  %s" % lab, textprops=dict(color="k"))
    viz = DrawingArea(15, 20, 0, 0)
    fontsize = 10
    key = mlines.Line2D([0.5*fontsize], [0.75*fontsize], marker=marker,
                               markersize=(0.5*fontsize), c="k")
    viz.add_artist(key)
    return HPacker(children=[viz, label], align="center", pad=5, sep=0)
开发者ID:adslyw,项目名称:ggplot,代码行数:12,代码来源:legend.py

示例8: make_size_key

def make_size_key(label, size):
    label = round(label, 2)
    label = str(label)
    idx = len(label)
    pad = 20 - idx
    lab = label[:max(idx, 20)]
    pad = " "*pad
    label = TextArea(": %s" % lab, textprops=dict(color="k"))
    viz = DrawingArea(15, 20, 0, 0)
    fontsize = 10
    key = mlines.Line2D([0.5*fontsize], [0.75*fontsize], marker="o", 
                               markersize=size / 20., c="k")
    viz.add_artist(key)
    return HPacker(children=[viz, label], align="center", pad=5, sep=0)
开发者ID:289825496,项目名称:ggplot,代码行数:14,代码来源:legend.py

示例9: make_linestyle_key

def make_linestyle_key(label, style):
    idx = len(label)
    pad = 20 - idx
    lab = label[:max(idx, 20)]
    pad = " "*pad
    label = TextArea("  %s" % lab, textprops=dict(color="k"))
    viz = DrawingArea(30, 20, 0, 0)
    fontsize = 10
    x = np.arange(0.5, 2.25, 0.25) * fontsize
    y = np.repeat(0.75, 7) * fontsize

    key = mlines.Line2D(x, y, linestyle=style, c="k")
    viz.add_artist(key)
    return HPacker(children=[viz, label], align="center", pad=5, sep=0)
开发者ID:adslyw,项目名称:ggplot,代码行数:14,代码来源:legend.py

示例10: hbar

def hbar(plot, p, values, colors=None, height=16,
         xoff=0, yoff=0,
         halign=1, valign=0.5,
         xycoords='data', boxcoords=('offset points')):
    x, y = _xy(plot, p)
    h = height; w = sum(values) * height#; yoff=h*0.5
    da = DrawingArea(w, h)
    x0 = -sum(values)
    if not colors:
        c = _colors.tango()
        colors = [ c.next() for v in values ]
    for i, v in enumerate(values):
        if v: da.add_artist(Rectangle((x0,0), v*h, h, fc=colors[i], ec='none'))
        x0 += v*h
    box = AnnotationBbox(da, (x,y), pad=0, frameon=False,
                         xybox=(xoff, yoff),
                         xycoords=xycoords,
                         box_alignment=(halign,valign),
                         boxcoords=boxcoords)
    plot.add_artist(box)
    plot.figure.canvas.draw_idle()
开发者ID:rhr,项目名称:ivy,代码行数:21,代码来源:symbols.py

示例11: tipsquares

def tipsquares(plot, p, colors="r", size=15, pad=2, edgepad=10):
    """
    RR: Bug with this function. If you attempt to call it with a list as an
    argument for p, it will not only not work (expected) but it will also
    make it so that you can't interact with the tree figure (gives errors when
    you try to add symbols, select nodes, etc.) -CZ

    Add square after tip label, anchored to the side of the plot

    Args:
        plot (Tree): A Tree plot instance.
        p (Node): A Node object (Should be a leaf node).
        colors (str): olor of drawn square. Optional, defaults to 'r' (red)
        size (float): Size of square. Optional, defaults to 15
        pad: RR: I am unsure what this does. Does not seem to have visible
          effect when I change it. -CZ
        edgepad (float): Padding from square to edge of plot. Optional,
          defaults to 10.

    """
    x, y = _xy(plot, p)  # p is a single node or point in data coordinates
    n = len(colors)
    da = DrawingArea(size * n + pad * (n - 1), size, 0, 0)
    sx = 0
    for c in colors:
        sq = Rectangle((sx, 0), size, size, color=c)
        da.add_artist(sq)
        sx += size + pad
    box = AnnotationBbox(
        da,
        (x, y),
        xybox=(-edgepad, y),
        frameon=False,
        pad=0.0,
        xycoords="data",
        box_alignment=(1, 0.5),
        boxcoords=("axes points", "data"),
    )
    plot.add_artist(box)
    plot.figure.canvas.draw_idle()
开发者ID:rhr,项目名称:ivy,代码行数:40,代码来源:symbols.py

示例12: plot_rst

def plot_rst(xList, yList, fnameList):
    '''docstring for plot_rst()''' 
    fig = plt.gcf()
    fig.clf()
    ax =  plt.subplot2grid((5,1),(0, 0),rowspan = 4)
    #ax = plt.subplot(111)


    xy = (0.5, 0.7)



    offsetbox = TextArea("Test", minimumdescent=False)

    ab = AnnotationBbox(offsetbox, xy,
                        xybox=(1.02, xy[1]),
                        xycoords='data',
                        boxcoords=("axes fraction", "data"),
                        box_alignment=(0.,0.5),
                        arrowprops=dict(arrowstyle="->"))
    ax.add_artist(ab)


    from matplotlib.patches import Circle
    da = DrawingArea(20, 20, 0, 0)
    p = Circle((10, 10), 10)
    da.add_artist(p)

    xy = [0.3, 0.55]
    ab = AnnotationBbox(da, xy,
                        xybox=(1.02, xy[1]),
                        xycoords='data',
                        boxcoords=("axes fraction", "data"),
                        box_alignment=(0.,0.5),
                        arrowprops=dict(arrowstyle="->"))
                        #arrowprops=None)

    ax.add_artist(ab)




    # another image


    from matplotlib._png import read_png
    #fn = get_sample_data("./61.png", asfileobj=False)
    arr_lena = read_png("./61.png")
    imagebox = OffsetImage(arr_lena, zoom=0.2)
    xy = (0.1, 0.1)
    print fnameList
    for i in range(0,len(fnameList)):
        ax.add_artist(AnnotationBbox(imagebox, xy,
                            xybox=(0.1 + i*0.2, -0.15),
                            xycoords='data',
                            boxcoords=("axes fraction", "data"),
                            #boxcoords="offset points",
                            pad=0.1,
                            arrowprops=dict(arrowstyle="->",
                                            connectionstyle="angle,angleA=0,angleB=90,rad=3")
                            ))

    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)


    plt.draw()
    plt.show()
开发者ID:sunkaianna,项目名称:object_detection,代码行数:68,代码来源:cmp_obj.py

示例13: box

# Annotate the 1st position with another text box ('Test')
offsetbox = TextArea("Test", minimumdescent=False)

ab = AnnotationBbox(offsetbox, xy,
                    xybox=(1.02, xy[1]),
                    xycoords='data',
                    boxcoords=("axes fraction", "data"),
                    box_alignment=(0., 0.5),
                    arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)

# Define a 2nd position to annotate (don't display with a marker this time)
xy = [0.3, 0.55]

# Annotate the 2nd position with a circle patch
da = DrawingArea(20, 20, 0, 0)
p = Circle((10, 10), 10)
da.add_artist(p)

ab = AnnotationBbox(da, xy,
                    xybox=(1.02, xy[1]),
                    xycoords='data',
                    boxcoords=("axes fraction", "data"),
                    box_alignment=(0., 0.5),
                    arrowprops=dict(arrowstyle="->"))

ax.add_artist(ab)

# Annotate the 2nd position with an image (a generated array of pixels)
arr = np.arange(100).reshape((10, 10))
im = OffsetImage(arr, zoom=2)
开发者ID:dopplershift,项目名称:matplotlib,代码行数:31,代码来源:demo_annotation_box.py

示例14: make_rect

def make_rect(color, alpha, size = (20,6), height = 20):
    color = color if color != None else "k" # Default value if None
    viz = DrawingArea(30, height, 0, 1)
    viz.add_artist(Rectangle((0, 6), width=size[0], height=size[1],
                             alpha=alpha, fc=color))
    return viz
开发者ID:9629831527,项目名称:ggplot,代码行数:6,代码来源:legend.py

示例15: _init_legend_box


#.........这里部分代码省略.........
                legline = Line2D(xdata, ydata)
                self._set_artist_props(legline)
                legline.set_clip_box(None)
                legline.set_clip_path(None)
                lw = handle.get_linewidth()[0]
                dashes = handle.get_dashes()[0]
                color = handle.get_colors()[0]
                legline.set_color(color)
                legline.set_linewidth(lw)
                legline.set_dashes(dashes)
                handle_list.append(legline)

            elif isinstance(handle, RegularPolyCollection):

                #ydata = self._scatteryoffsets
                ydata = height*self._scatteryoffsets

                size_max, size_min = max(handle.get_sizes()),\
                                     min(handle.get_sizes())
                # we may need to scale these sizes by "markerscale"
                # attribute. But other handle types does not seem
                # to care about this attribute and it is currently ignored.
                if self.scatterpoints < 4:
                    sizes = [.5*(size_max+size_min), size_max,
                             size_min]
                else:
                    sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min

                p = type(handle)(handle.get_numsides(),
                                 rotation=handle.get_rotation(),
                                 sizes=sizes,
                                 offsets=zip(xdata_marker,ydata),
                                 transOffset=self.get_transform(),
                                 )

                p.update_from(handle)
                p.set_figure(self.figure)
                p.set_clip_box(None)
                p.set_clip_path(None)
                handle_list.append(p)

            else:
                handle_list.append(None)

            handlebox = DrawingArea(width=self.handlelength*fontsize,
                                    height=height,
                                    xdescent=0., ydescent=descent)

            handle = handle_list[-1]
            handlebox.add_artist(handle)
            if hasattr(handle, "_legmarker"):
                handlebox.add_artist(handle._legmarker)
            handleboxes.append(handlebox)


        # We calculate number of lows in each column. The first
        # (num_largecol) columns will have (nrows+1) rows, and remaing
        # (num_smallcol) columns will have (nrows) rows.
        nrows, num_largecol = divmod(len(handleboxes), self._ncol)
        num_smallcol = self._ncol-num_largecol

        # starting index of each column and number of rows in it.
        largecol = safezip(range(0, num_largecol*(nrows+1), (nrows+1)),
                           [nrows+1] * num_largecol)
        smallcol = safezip(range(num_largecol*(nrows+1), len(handleboxes), nrows),
                           [nrows] * num_smallcol)

        handle_label = safezip(handleboxes, labelboxes)
        columnbox = []
        for i0, di in largecol+smallcol:
            # pack handleBox and labelBox into itemBox
            itemBoxes = [HPacker(pad=0,
                                 sep=self.handletextpad*fontsize,
                                 children=[h, t], align="baseline")
                         for h, t in handle_label[i0:i0+di]]
            # minimumdescent=False for the text of the last row of the column
            itemBoxes[-1].get_children()[1].set_minimumdescent(False)

            # pack columnBox
            columnbox.append(VPacker(pad=0,
                                        sep=self.labelspacing*fontsize,
                                        align="baseline",
                                        children=itemBoxes))

        if self._mode == "expand":
            mode = "expand"
        else:
            mode = "fixed"

        sep = self.columnspacing*fontsize

        self._legend_box = HPacker(pad=self.borderpad*fontsize,
                                      sep=sep, align="baseline",
                                      mode=mode,
                                      children=columnbox)

        self._legend_box.set_figure(self.figure)

        self.texts = text_list
        self.legendHandles = handle_list
开发者ID:08s011003,项目名称:nupic,代码行数:101,代码来源:legend.py


注:本文中的matplotlib.offsetbox.DrawingArea类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。