pygrace.extensions module documentation

colorbar module

class ColorBar(domain=(), scale='Normal', autoscale=True, reverse=False, color_range=(), *args, **kwargs)

Bases: Graph

__str__()

Override the __str__ functionality to draw the colorbar at draw time.

_epsilon()

This is used to slightly alter the domain to correctly match values with colors that belong on this colorbar.

add_colors()

add colors first two colors are white and black, skip them

autoscalex(pad=0, only_visible=True)

Over ride autoscale behavior of Graph.

autoscaley(pad=0, only_visible=True)

Over ride autoscale behavior of Graph.

color2zs(color)

Get the range of values (zs) associated with a particular color, color.

get_domain()
set_domain(domain, autoscale=True, pad=0)

set the domain of the yaxis by (1) adding a dummy dataset, (2) autoscaling, and (3) removing dummy dataset.

set_label(label)

Set the axis label.

set_scale(scale)
z2color(z)

Get the color that is associated with a particular value, z.

class SolidOutlinedRectangle(color, outline_color=1, *args, **kwargs)

Bases: DataSet

A dataset that shows up as a solid rectangle with an outline.

data for the creating of the SolidOutlinedRectangle must be the two corners of the rectangle.

class SolidPixelatedShape(color, pixelsize=None, square_pixels=True, *args, **kwargs)

Bases: DataSet

A dataset that shows up as a solid object. The shape can be anything made up of squares. The data is given as the (x,y) values of pixels. If pixel size is not given, this acquires it automatically from the data (min distance between neighboring pixels).

Traces the outer line of the shape defined by the pixels. The trace is greedy, if there are holes in the middle of the shape, they will be filled.

This is way more efficient compared to drawing a single color object box by box (pixel by pixel). It’s useful in cases where you have a data matrix with a large region of the same color. The major functionality is tracing the outline of a region.

data should be a list of tuples in [(x1,y1), (x2,y2), …] form. Each tuple is the center coordinate of a pixel.

class SolidRectangle(color, *args, **kwargs)

Bases: DataSet

A dataset that shows up as a solid rectangle.

data for the creating of the SolidRectangle must be the two corners of the rectangle.

distribution module

class CDFGraph(data, fancy_dots, *args, **kwargs)

Bases: DistributionGraph

_interlace(listA, listB)
class DistributionGraph(data, *args, **kwargs)

Bases: Graph

class PDFGraph(data, *args, **kwargs)

Bases: DistributionGraph

latex_string module

class LatexString

Bases: str

__add__(other)

Return self+value.

__radd__(other)
__str__()

Return str(self).

multi_plot module

class MultiPlotProject(rows=None, cols=None, hgap=0.1, vgap=0.1, hoffset=(0.15, 0.05), voffset=(0.05, 0.15), width_to_height_ratio=1.4285714285714286, multi_graphs=(), *args, **kwargs)

Bases: Project

_calculate_graph_frame()
align_axislabel(xplace_tup=(0, 0.08), yplace_tup=(0, 0.08))

Align the x- and y-axis labels with place_tup for all graphs in this Project instance.

align_axislabelx(place_tup=(0, 0.08))

Align the x-axis labels with place_tup for all graphs in this Project instance.

align_axislabely(place_tup=(0, 0.08))

Align the y-axis labels with place_tup for all graphs in this Project instance.

automulti(maxrows=5, maxcols=7, hoffset=(0.15, 0.05), voffset=(0.05, 0.15), hgap=0.1, vgap=0.1, width_to_height_ratio=1.4285714285714286, multi_graphs=())

Automatically determine the number of rows and columns to add based on the number of graphs currently in the grace. The number of rows and columns is determined by trying to maximize the area of canvas that is used (by a non-optimized brute force approach).

get_rc(row, col)

Returns the graph in position [row][col]

hide_redundant_axislabels()

Hide all redundant axis labels.

hide_redundant_labels()

Hide all redundant axis and tick labels.

hide_redundant_ticklabels()

Hide all redundant tick labels.

hide_redundant_xaxislabels()

Hide all x-axis axis labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

hide_redundant_xlabels()

Hide all x-axis tick and axis labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

hide_redundant_xticklabels()

Hide all x-axis tick labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

hide_redundant_yaxislabels()

Hide all y-axis axis labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

hide_redundant_ylabels()

Hide all y-axis tick and axis labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

hide_redundant_yticklabels()

Hide all y-axis tick labels on the interior of a multigraph that are redundant, but only if all labels on the interior of the multigraph are the same.

multi(rows, cols, hoffset=(0.15, 0.05), voffset=(0.05, 0.15), hgap=0.1, vgap=0.1, width_to_height_ratio=1.4285714285714286, multi_graphs=())

Create a grid of graphs with the given number of <rows> and <cols> Makes graph frames all the same size.

put(g, row, col)
set_col_yaxislabel(col, label, perpendicular_offset=0.08, opposite_side=False, rowspan=(None, None), *args, **kwargs)

Add a single y-axis label to a particular column of multi plot. rowspan specifies the rows that label spans. To span over rows 0-1, for example, specify rowspan=(0,1). rowspan=(None,None) is default and understood to mean all rows in that column.

set_row_xaxislabel(row, label, perpendicular_offset=0.08, opposite_side=False, colspan=(None, None), *args, **kwargs)

Add a single x-axis label to a particular row of multi plot. colspan specifies the cols that label spans. To span over cols 0-1, for example, specify colspan=(0,1). colspan=(None,None) is default and understood to mean all cols in that row.

network module

class Bezier(x0, y0, x1, y1, curvature=0)

Bases: object

Quadratic Bezier curve

change_curvature(new_curvature)
change_middle_point(new_xc, new_yc)
curve_function(t)

a function that returns a point on the curve. t is between [0,1]. At t=0, the curve is at x0,y0 At t=1, the curve is at x1,y1

points(n)

returns n points as a list of tuples: [(x0,y0), (xa,ya), (xb,yb), … , (xk,yk), (x1,y1)]

class DirectedLinkSet(size=1, color=1, avoid_crossing_nodes=True, put_arrows=True, curvature=0.6, arrow_position=0.75, *args, **kwargs)

Bases: LinkSet

Also a dataset containing network links.

The links are directed. They can have arrows, they can curve around nodes on their path and they can be given a default curvature to be able to show both forward and backward connections between two nodes (the default is slightly to the right). Other than that, they are the same as LinkSet.

class LinkSet(size=1, color=1, ignore_missing=False, *args, **kwargs)

Bases: DataSet

A dataset containing network links.

Link in the same dataset can be treated as any dataset in xmgrace, which means that color, width, and so on can be changed simultaneously for all links in the set. In general, a LinkSet can take advantage of any of the properties of regular DataSets.

data for the creation of a link needs to be a list of node pairs.

Nodes with the right labels need to have been added to the network before their links can be added. Otherwise, a ValueError is raised (unless the keyword ignore_missing is set to True, in which case the link is ignored and there is only a warning sent to stderr).

class Network(bounding_box=False, *args, **kwargs)

Bases: Graph

A graph to display networks.

Add a single directed link to the graph.

The link will be added to the Network graph as a DirectedLinkSet.

-node_pair needs to be a pair of nodes (label1, label2), and the corresponding nodes need to exist in the network already.

Add a bunch of directed links to the graph.

Links will be added to the Network graph as a DirectedLinkSet.

-node_pairs needs to be a pair of nodes (label1, label2), and the corresponding nodes need to exist in the network already.

Add a single link to the graph.

The link will be added to the Network graph as a LinkSet.

-node_pair needs to be a pair of nodes (label1, label2), and the corresponding nodes need to exist in the network already.

Add a bunch of links to the graph.

Links will be added to the Network graph as a LinkSet.

-node_pairs needs to be a list of pairs of nodes (label1, label2), and the corresponding nodes need to exist in the network already.

add_node(label, node_data, size=1, color=1, line_width=1, line_color=1, *args, **kwargs)

Add a single node to the graph.

The node will be added to the Network graph as a NodeSet.

-label contains the label of the node.

-node_data needs to be the (x,y) coordinates of the node (or (x,y,size), (x,y,color), and so on if the type is ‘xysize’, ‘xycolor’, and so on).

add_node_set(node_data, size=1, color=1, line_width=1, line_color=1, *args, **kwargs)

Add a bunch of nodes to the graph.

Nodes will be added to the Network graph as a NodeSet.

-node_data needs to be a dictionary indexed by the nodes’ labels, and whose values are the (x,y) coordinates of the nodes (or (x,y,size), (x,y,color), and so on if the type is ‘xysize’, ‘xycolor’, and so on).

class NodeSet(size=1, color=1, line_width=1, line_color=1, shape=1, labels=False, *args, **kwargs)

Bases: DataSet

A dataset containing network nodes.

Nodes in the same dataset can be treated as any dataset in xmgrace, which means that color, size, and so on can be changed simultaneously for all nodes in the set. In general, a NodeSet can take advantage of any of the properties of regular DataSets. For example, a type=’xysize’ NodeSet has nodes with different sizes, and a type=’xycolor’ dataset contains nodes with different colors.

-data (see DataSet definition) needs to be a dictionary indexed by the nodes’ labels, and whose values are the (x,y) coordinates of the nodes (or (x,y,size), (x,y,color), and so on if the type is ‘xysize’, ‘xycolor’, and so on).

panel module

class MultiPanelProject(label_scheme='LATIN', *args, **kwargs)

Bases: MultiPlotProject

Project object to hold panel schemes.

add_graph(cls=<class 'pygrace.extensions.panel.Panel'>, *args, **kwargs)

Overwrite the add_graph of Project base so that the default argument is a panel

add_label_scheme(label_scheme, labels)

Add a label scheme to this Project.

place_labels(placement=None, dx=None, dy=None, just=None)

Place all labels in grace at the same time.

set_label_scheme(label_scheme)

Specify the label scheme for the grace and all panels in the grace.

class NetworkPanel(*args, **kwargs)

Bases: Panel, Network

A panel to display networks.

class Panel(panel_index=None, *args, **kwargs)

Bases: Graph

A Panel is a Graph that has a panel label.

class PanelLabel(parent, index=None, dx=0.05, dy=0.05, placement='iur', label_scheme=None, *args, **kwargs)

Bases: DrawText

This class is useful for adding panel labels to figures. Note that dx and dy are automatically adjusted to correctly space the

index = index of labelling scheme

dx,dy = Spatial offset from Panel corner. Direction of dx changes

depending on placement specification.

placement = ‘iur’ (inside upper right), ‘our’ (outside upper right),

‘ilr’ (inside lowr right), etc.

__str__()

Override the __str__ functionality to draw the PanelLabel at draw time.

place_label(placement=None, dx=None, dy=None, just=None)

Place the PanelLabel near with format placement and position dx and dy, which are measured as the fraction of the length of the longest side of the frame of the Panel (its parent). This method requires no arguments, but you can specify placement, dx, and dy optionally. You can also additionally optionally specify the justification with ‘just’, which will override the default behavior of a PanelLabel which automatically justifies this feature.

This method is called at draw time to correctly place the label.

set_text(label_scheme=None, index=None)

Set the text of the panel label at draw time based on the label_scheme and the index.

class TreePanel(*args, **kwargs)

Bases: Panel, Tree

A panel to display trees.

table module

class DrawTable(table, char_size=1.65, xSpace=0.1, ySpace=0.05, color=1, font=4, lowleft=(0.5, 0.5), loctype='view', *args, **kwargs)

Bases: DrawingObject

tree module

class Tree(parent, orientation='right', **kwargs)

Bases: Graph

A graph to display trees (such as phylogenetic trees).

__setattr__(key, value)

Implement setattr(self, name, value).

add_tree(tree_data, size=1, color=1, line_width=1, line_color=1, *args, **kwargs)

Add a tree to the graph.

The tree is a string argument that contains the tree information. The string must follow the Newick tree format (also known as Newick notation or New Hampshire tree format). See http://en.wikipedia.org/wiki/Newick_format for details.

The tree will be added to the Tree graph as a DataSet. The labels will be added as special tick labels.