Example #1
0
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()
Example #2
0
File: symbols.py Project: rhr/ivy
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
Example #3
0
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
Example #4
0
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()
Example #5
0
from matplotlib.figure import SubplotParams, Figure
from matplotlib.axes import SubplotBase, Axes, subplot_class_factory
from matplotlib.patches import PathPatch, Rectangle
from matplotlib.path import Path
from matplotlib.widgets import RectangleSelector
from matplotlib.transforms import Bbox, offset_copy
from matplotlib import cm as mpl_colormap
from matplotlib import colors as mpl_colors
from matplotlib.colorbar import Colorbar
from matplotlib.collections import RegularPolyCollection
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import shapes, colors

matplotlib.rcParams['path.simplify'] = False

_tango = colors.tango()

class TreeFigure:
    """
    Window for showing a single tree, optionally with split overview
    and detail panes.

    The navigation toolbar at the bottom is provided by matplotlib
    (http://matplotlib.sf.net/users/navigation_toolbar.html).  Its
    pan/zoom button and zoom-rectangle button provide different modes
    of mouse interaction with the figure.  When neither of these
    buttons are checked, the default mouse bindings are as follows:

    * button 1 drag: select nodes - retrieve by calling fig.selected_nodes()
    * button 3 drag: pan view
    * scroll up/down: zoom in/out