ivy.vis package¶
Submodules¶
ivy.vis.alignment module¶
interactive viewers for trees, etc. using matplotlib
- 
class ivy.vis.alignment.Alignment(fig, rect, *args, **kwargs)[source]¶
- Bases: - matplotlib.axes._axes.Axes- matplotlib.axes.Axes subclass for rendering sequence alignments. 
ivy.vis.axes_utils module¶
ivy.vis.bokehtree module¶
Viewer for trees using Bokeh
- 
class ivy.vis.bokehtree.BokehTree(root, scaled=True, nodelabels=True, tiplabels=True, showplot=True, hover=False)[source]¶
- Bases: - object
ivy.vis.events module¶
Events for tree figures
- 
class ivy.vis.events.UpdatingRect(xy, width, height, angle=0.0, **kwargs)[source]¶
- Bases: - matplotlib.patches.Rectangle
ivy.vis.hardcopy module¶
- 
class ivy.vis.hardcopy.TreeFigure(root, relwidth=0.5, leafpad=1.5, name=None, support=70.0, scaled=True, mark_named=True, leaf_fontsize=10, branch_fontsize=10, branch_width=1, branch_color=u'black', highlight_support=True, branchlabels=True, leaflabels=True, layers=[], xoff=0, yoff=0, xlim=None, ylim=None, height=None, width=None, plottype=u'phylogram')[source]¶
- 
- 
detail¶
 - 
render_multipage(outfile, pagesize=[8.5, 11.0], dims=None, border=0.393701, landscape=False)[source]¶
- Create a multi-page PDF document where the figure is cut into multiple pages. Used for printing large figures. - Parameters: - outfile (string) – The path to the output file.
- pagesize (list) – Two floats. Page size of each individual page in inches. Defaults to 8.5 x 11.0.
- dims (list) – Two floats. The dimensions of the final figure in inches. Defaults to the original size of the figure.
- border (float) – The amount of overlap (in inches) between each page to make taping them together easier. Defaults to 0.393701 (1 cm)
- landscape (bool) – Whether or not each page will be in landscape orientation. Defaults to false.
 
 
- 
ivy.vis.layers module¶
Layer functions to add to a tree plot with the addlayer method
- 
ivy.vis.layers.add_ancestor_noderecon(treeplot, internal_vals, vis=True, colors=None, nregime=None, size=8)[source]¶
- Add piecharts at each node based on probability vector - Parameters: - internal_vals – - Array of dimensions [nchar+2, nnodes]. Identical to the
- format returned by anc_recon_cat
 - colors: List of length = nchar. The colors for each character. Optional. nregime: Number of regimes. If given and colors = None, function will automatically color-code characters by regime. (NOT IMPLEMENTED) 
- 
ivy.vis.layers.add_ancrecon(treeplot, liks, vis=True, width=2)[source]¶
- Plot ancestor reconstruction for a binary mk model 
- 
ivy.vis.layers.add_ancrecon_hrm(treeplot, liks, vis=True, width=2)[source]¶
- Color branches on tree based on likelihood of being in a state based on ancestral state reconstruction of a two-character, two-regime hrm model. 
- 
ivy.vis.layers.add_branchstates(treeplot, vis=True, colors=None)[source]¶
- Add simulated branch states. - Treeplot must have simulated states as attributes 
- 
ivy.vis.layers.add_cbar(treeplot, nodes, vis=True, color=None, label=None, x=None, width=8, xoff=10, showlabel=True, mrca=True, leaf_valign=u'center', leaf_halign=u'left', leaf_fontsize=10, leaf_offset=4)[source]¶
- Draw a ‘clade’ bar (i.e., along the y-axis) indicating a clade. nodes are assumed to be one or more nodes in the tree. If just one, it should be the internal node representing the clade of interest; otherwise, the clade of interest is the most recent common ancestor of the specified nodes. label is an optional string to be drawn next to the bar, offset by the specified number of display units. If label is - Nonethen the clade’s label is used instead.- Parameters: - nodes – Node or list of nodes or string or list of strings.
- color (str) – Color of the bar. Optional, defaults to None. If None, will cycle through a color palette
- label (str) – Optional label for bar. If None, the clade’s label is used instead. Defaults to None.
- width (float) – Width of bar
- x (float) – Distance from tip of tree to bar. Optional, if None, calculated based on leaf labels.
- xoff (float) – Offset from label to bar
- showlabel (bool) – Whether or not to draw the label
- mrca (bool) – Whether to draw the bar encompassing all descendants
of the MRCA of nodes
 
- 
ivy.vis.layers.add_circles(treeplot, nodes, colors=u'g', size=15, xoff=0, yoff=0, vis=True)[source]¶
- Draw circles on plot at nodes - Parameters: - nodes – A node object or list of Node objects or label or list of labels
- colors – Str or list of strs. Colors of the circles. Optional, defaults to ‘g’ (green)
- size (float) – Size of the circles. Optional, defaults to 15
- yoff (xoff,) – X and Y offset. Optional, defaults to 0.
 
- 
ivy.vis.layers.add_circles_branches(treeplot, nodes, distances, colors=u'g', size=15, xoff=0, yoff=0, vis=True)[source]¶
- Draw circles on branches - Parameters: - nodes – A node object or list of Node objects or label or list of labels
- distances – Float or list of floats indicating the distance from the parent node the branch should be drawn on.
- colors – Str or list of strs. Colors of the circles. Optional, defaults to ‘g’ (green)
- size (float) – Size of the circles. Optional, defaults to 15
- yoff (xoff,) – X and Y offset. Optional, defaults to 0.
 
- 
ivy.vis.layers.add_highlight(treeplot, x=None, vis=True, width=5, color=u'red')[source]¶
- Highlight nodes - Parameters: 
- Color branches based on likelihood of being in hidden states. - Parameters: - liks (np.array) – The output of anc_recon run as a hidden-rates reconstruction. 
- 
ivy.vis.layers.add_image(treeplot, x, imgfiles, maxdim=100, border=0, xoff=4, yoff=4, halign=0.0, valign=0.5, xycoords=u'data', boxcoords=u'offset points')[source]¶
- Add images to a plot at the given nodes. - Parameters: - x – Node/label or list of nodes/labels.
- imgfiles – String or list of strings of image files
 - Note - x and imgfiles must be the same length 
- 
ivy.vis.layers.add_label(treeplot, labeltype, vis=True, leaf_offset=4, leaf_valign=u'center', leaf_halign=u'left', leaf_fontsize=10, branch_offset=-5, branch_valign=u'center', branch_halign=u'right', fontsize=u'10')[source]¶
- Add text labels to tree - Parameters: - treeplot – treeplot (fig.tree)
- labeltype (str) – “leaf” or “branch”
 
- 
ivy.vis.layers.add_legend(treeplot, colors, labels, shape=u'rectangle', loc=u'upper left', **kwargs)[source]¶
- Add legend mapping colors/shapes to labels - Parameters: 
- 
ivy.vis.layers.add_mkmr_heatmap(treeplot, locations, vis=True, seglen=0.02)[source]¶
- Heatmap that shows which portions of the tree are most likely to contain a switchpoint - To be used with the output from mk_multi_bayes. - Parameters: 
- 
ivy.vis.layers.add_node_heatmap(treeplot, nodelist, vis=True)[source]¶
- Plot circles on nodes with colors indicating how frequently each node appears in nodelist. For use with plotting potential regime shift locations - Parameters: - nodelist (list) – list of node objects. Repeats allowed (and expected) 
- 
ivy.vis.layers.add_phylorate(treeplot, rates, nodeidx, vis=True)[source]¶
- Add phylorate plot generated from data analyzed with BAMM (http://bamm-project.org/introduction.html) - Parameters: - Warning - Ladderizing the tree can cause incorrect assignment of Ape node index numbers. To prevent this, call this function or root.ape_node_idx() before ladderizing the tree to assign correct Ape node index numbers. 
- 
ivy.vis.layers.add_pie(treeplot, node, values, colors=None, size=16, norm=True, xoff=0, yoff=0, halign=0.5, valign=0.5, xycoords=u'data', boxcoords=u'offset points', vis=True)[source]¶
- Draw a pie chart - Args: node (Node): A single Node object or node label 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
- 
ivy.vis.layers.add_squares(treeplot, nodes, colors=u'r', size=15, xoff=0, yoff=0, alpha=1.0, vis=True)[source]¶
- Draw a square at given node - Parameters: - p – A node or list of nodes or string or list of strings
- colors – Str or list of strs. Colors of squares to be drawn. Optional, defaults to ‘r’ (red)
- size (float) – Size of the squares. Optional, defaults to 15
- yoff (xoff,) – Offset for x and y dimensions. Optional, defaults to 0.
- alpha (float) – between 0 and 1. Alpha transparency of squares. Optional, defaults to 1 (fully opaque)
- zorder (int) – The drawing order. Higher numbers appear on top of lower numbers. Optional, defaults to 1000.
 
- 
ivy.vis.layers.add_text(treeplot, x, y, s, color=u'black', xoff=0, yoff=0, valign=u'center', halign=u'left', fontsize=10)[source]¶
- Add text to the plot. - Parameters: - y (x,) – x and y coordinates to place the text
- s (str) – The text to write
- color (str) – The color of the text. Optional, defaults to “black”
- yoff (xoff,) – x and y offset
- valign (str) – Vertical alignment. Can be: ‘center’, ‘top’, ‘bottom’, or ‘baseline’. Defaults to ‘center’.
- halign (str) – Horizontal alignment. Can be: ‘center’, ‘right’, or ‘left’. Defaults to ‘left’
- fontsize (float) – Font size. Optional, defaults to 10
 
- 
ivy.vis.layers.add_tree_heatmap(treeplot, locations, vis=True, color=(1, 0, 0))[source]¶
- Plot how often tree coordinates appear in locations - Parameters: - locations (list) – List of tuples where first item is node, second item is how far from the node’s parent the location is. 
- 
ivy.vis.layers.color_blender_1(value, start, end)[source]¶
- Smooth transition between two values - value (float): Percentage along color map start: starting value of color map end: ending value of color map 
- 
ivy.vis.layers.color_map(value, col1, col2)[source]¶
- Return RGB for value based on minimum and maximum colors 
- 
ivy.vis.layers.colorbar_legend(ax, values, cmap, vis=True)[source]¶
- Add a vertical colorbar legend to a plot 
- 
ivy.vis.layers.gradient_segment_horz(p1, p2, c1, c2, width=4)[source]¶
- Create a horizontal segment that is filled with a gradient - Parameters: - Returns: - list of segs and colors to be added to a LineCollection - Return type: 
ivy.vis.matplot module¶
ivy.vis.tree module¶
ivy.vis.treevis module¶
interactive viewers for trees, etc. using matplotlib
Re-written to have a layer-based API
- 
class ivy.vis.treevis.MultiTreeFigure(trees=None, name=None, support=70, scaled=True, branchlabels=False, radial=False)[source]¶
- Bases: - ivy.vis.treevis.TreeFigure- Class for drawing multiple trees in one figure 
- 
class ivy.vis.treevis.OverviewTree(*args, **kwargs)[source]¶
- Bases: - ivy.vis.treevis.Tree
- 
class ivy.vis.treevis.RadialTree(fig, rect, tf=None, *args, **kwargs)[source]¶
- Bases: - ivy.vis.treevis.Tree- Matplotlib axes subclass for rendering radial trees 
- 
class ivy.vis.treevis.Tree(fig, rect, tf=None, *args, **kwargs)[source]¶
- Bases: - matplotlib.axes._axes.Axes- Subclass for rendering trees - 
window2data(expandx=1.0, expandy=1.0)[source]¶
- return the data coordinates ((x0, y0),(x1, y1)) of the plot window, expanded by relative units of window size 
 - 
zoom(x=0.1, y=0.1, cx=None, cy=None)[source]¶
- Zoom the x and y axes in by the specified proportion of the current view. 
 
- 
- 
class ivy.vis.treevis.TreeFigure(data, name=None, scaled=True, div=0.25, branchlabels=True, leaflabels=True, xoff=0, yoff=0, mark_named=True, overview=True, interactive=True, radial=False, leaf_fontsize=10, branch_fontsize=10, direction=u'rightwards')[source]¶
- Bases: - object- mpl Figure for plotting trees. - Holds references to all layers:
- Tree (the base layer: the Axes which all other layers are drawn on)
- Node labels
- Tip labels
- Overview
- Decorators
- Etc.
 - 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
- button 3 drag: pan view
- scroll up/down: zoom in/out
- scroll up/down with Control key: zoom y-axis
- scroll up/down with Shift key: zoom x-axis
- scroll up/down with ‘d’ key: pan view up/down
- scroll up/down with ‘e’ key: pan view left/right
- click on overview will center the detail pane on that region
 - Default keybindings: - t: zoom out to full extent
- +/-: zoom in/out
 - Useful attributes and methods (assume an instance named fig): - fig.root - the root node (see [Node methods])
- fig.highlight(s) - highlight and trace nodes with substring s
- fig.zoom_clade(anc) - zoom to view node anc and all its descendants
- fig.toggle_overview() - toggle visibility of the overview pane
- fig.toggle_branchlabels() - ditto for branch labels
- fig.toggle_leaflabels() - ditto for leaf labels
- fig.decorate(func) - decorate the tree with a function (see decorating TreeFigures)
 - 
add_layer(func, *args, **kwargs)[source]¶
- Add a new layer. New layers include: - Labels
- Overview
- Dataplot
- Decorations
 - Parameters: - func (function) – Function that takes a TreePlot (self.tree) as input and returns (and draws) an Artist - Keyword Arguments: - store (str) – Name of layer. If given, the layer is stored in self.layers and called upon every redraw 
 - 
axes¶
 - 
cbar(nodes, *args, **kwargs)[source]¶
- Convenience function for adding clade bar along y axis - Draw a ‘clade’ bar (i.e., along the y-axis) indicating a clade. nodes are assumed to be one or more nodes in the tree. If just one, it should be the internal node representing the clade of interest; otherwise, the clade of interest is the most recent common ancestor of the specified nodes. label is an optional string to be drawn next to the bar, offset by the specified number of display units. If label is - Nonethen the clade’s label is used instead.- Parameters: - nodes – Node or list of nodes or string or list of strings.
- color (str) – Color of the bar. Optional, defaults to None. If None, will cycle through a color palette
- label (str) – Optional label for bar. If None, the clade’s label is used instead. Defaults to None.
- width (float) – Width of bar
- xoff (float) – Offset from label to bar
- showlabel (bool) – Whether or not to draw the label
- mrca (bool) – Whether to draw the bar encompassing all descendants
of the MRCA of nodes
 
 - 
find(x)[source]¶
- Find nodes - Parameters: - x (str) – String to search - Returns: - A list of node objects found with the Node findall() method - Return type: - list 
 - 
initialize_subplots(overview=True, leaf_fontsize=10, branch_fontsize=10)[source]¶
- Initialize treeplot (a matplotlib.axes.Axes) and add it to the figure. Also initialize overview. If overview=False, toggle off overview. 
 - 
remove_layer(layername)[source]¶
- Remove a layer by name. - Parameters: - layername (str) – Name of the layer to remove. See all layers with self.layers 
 - 
reorder_layers(neworder)[source]¶
- Reorder layers and redraw figure - Parameters: - neworder (list) – New order of layers. Must include all layers currently in the figure. See all layers with fig.layers 
 - 
select_nodes(nodes=None)[source]¶
- Select nodes on the plot - Parameters: - nodes – A node or list of ndoes - Notes - If only one node is given, all of the node’s ancestors are also selected. If a list of nodes is given (even if it has only one node), only the given node(s) are selected. 
 - 
selected¶
 - 
tipstates(chars, nodes=None, colors=None, *args, **kwargs)[source]¶
- Convenience function for drawing color-coded circles at tips indicating character states. - Parameters: - chars (dict) – Dict mapping character states to tip labels. Character states should be coded 0,1,2... Can also be a list with tip states in preorder sequence 
- nodes (list) – List of nodes or node labels. Optional, defaults to all tip labels in preorder sequence
- colors (list) – List of strs of the same length as the number of unique characters. Optional, defaults to tango colorscheme
 
- chars (dict) – 
 - 
toggle_branchlabels(val=None)[source]¶
- Toggle visibility of branchlabels (equivalent to toggle_layer(“branchlabels”)) 
 - 
toggle_layer(layername, val=None)[source]¶
- Set a layer to be visible/invisible (but still stored in self.layers) - Parameters: - layername (str) – Name of the layer to toggle. See all layers with self.layers. 
 - 
toggle_leaflabels(val=None)[source]¶
- Toggle visibility of leafabels (equivalent to self.toggle_layer(“leaflabels”))