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
None
then 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”))