gnome.utilities.graphs.graph

A MatPlotLib graphing class. Here we encapsulate the built-in API of MatPlotLib and pyplot into a class that is hopefully easier to use.

Note

There is a rich graphing package called seaborn that piggybacks on top of MatPlotLib which we may eventually want to use.

One very important reason for making this class, besides ease of use, is that MatPlotLib objects can not be directly persisted into a formatted file. On the mpl forums that I have visited, most have suggested that the data be persisted if it is difficult to reproduce, and a plot be generated from data when needed.

The data needed for graphing is contained in this class, and a render() method acts upon the contained data. Thus, this class, along with py_gnomes persistence infrastructure, will allow us to save and recall graph objects from cache, as well as serialize and deserialize them.

This is meant to be a usable base class that behaves in a general manner. But it is also intended to be easily customizable through sub-classing.

Module Contents

Classes

PointSeries

Fundamental building block of schemas.

Points

Fundamental building block of schemas.

Labels

Fundamental building block of schemas.

Formats

Fundamental building block of schemas.

Graph

A class for assigning a unique ID for an object

Attributes

np

mpl

plt

dg

gnome.utilities.graphs.graph.np
gnome.utilities.graphs.graph.mpl
gnome.utilities.graphs.graph.plt
class gnome.utilities.graphs.graph.PointSeries(*args, **kw)

Bases: colander.SequenceSchema

Fundamental building block of schemas.

The constructor accepts these positional arguments:

  • typ: The ‘type’ for this node. It should be an instance of a class that implements the colander.interfaces.Type interface. If typ is not passed, a call to the schema_type() method on this class is made to get a default type. (When subclassing, schema_type() should be overridden to provide a reasonable default type).

  • *children: a sequence of subnodes. If the subnodes of this node are not known at construction time, they can later be added via the add method.

The constructor accepts these keyword arguments:

  • name: The name of this node.

  • typ: The ‘type’ for this node can optionally be passed in as a keyword argument. See the documentation for the positional arg above.

  • default: The default serialization value for this node when not set. If default is colander.drop, the node will be dropped from schema serialization. If not provided, the node will be serialized to colander.null.

  • missing: The default deserialization value for this node. If it is not provided, the missing value of this node will be the special marker value colander.required, indicating that it is considered ‘required’. When missing is colander.required, the required computed attribute will be True. When missing is colander.drop, the node is dropped from the schema if it isn’t set during deserialization.

  • missing_msg: Optional error message to be used if the value is required and missing.

  • preparer: Optional preparer for this node. It should be an object that implements the colander.interfaces.Preparer interface.

  • validator: Optional validator for this node. It should be an object that implements the colander.interfaces.Validator interface.

  • after_bind: A callback which is called after a clone of this node has ‘bound’ all of its values successfully. This callback is useful for performing arbitrary actions to the cloned node, or direct children of the cloned node (such as removing or adding children) at bind time. A ‘binding’ is the result of an execution of the bind method of the clone’s prototype node, or one of the parents of the clone’s prototype nodes. The deepest nodes in the node tree are bound first, so the after_bind methods of the deepest nodes are called before the shallowest. The after_bind callback should accept two values: node and kw. node will be a clone of the bound node object, kw will be the set of keywords passed to the bind method.

  • title: The title of this node. Defaults to a titleization of the name (underscores replaced with empty strings and the first letter of every resulting word capitalized). The title is used by higher-level systems (not by Colander itself).

  • description: The description for this node. Defaults to '' (the empty string). The description is used by higher-level systems (not by Colander itself).

  • widget: The ‘widget’ for this node. Defaults to None. The widget attribute is not interpreted by Colander itself, it is only meaningful to higher-level systems such as Deform.

  • insert_before: if supplied, it names a sibling defined by a superclass for its parent node; the current node will be inserted before the named node. It is not useful unless a mapping schema is inherited from another mapping schema, and you need to control the ordering of the resulting nodes.

Arbitrary keyword arguments remaining will be attached to the node object unmolested.

point
class gnome.utilities.graphs.graph.Points(*args, **kw)

Bases: colander.SequenceSchema

Fundamental building block of schemas.

The constructor accepts these positional arguments:

  • typ: The ‘type’ for this node. It should be an instance of a class that implements the colander.interfaces.Type interface. If typ is not passed, a call to the schema_type() method on this class is made to get a default type. (When subclassing, schema_type() should be overridden to provide a reasonable default type).

  • *children: a sequence of subnodes. If the subnodes of this node are not known at construction time, they can later be added via the add method.

The constructor accepts these keyword arguments:

  • name: The name of this node.

  • typ: The ‘type’ for this node can optionally be passed in as a keyword argument. See the documentation for the positional arg above.

  • default: The default serialization value for this node when not set. If default is colander.drop, the node will be dropped from schema serialization. If not provided, the node will be serialized to colander.null.

  • missing: The default deserialization value for this node. If it is not provided, the missing value of this node will be the special marker value colander.required, indicating that it is considered ‘required’. When missing is colander.required, the required computed attribute will be True. When missing is colander.drop, the node is dropped from the schema if it isn’t set during deserialization.

  • missing_msg: Optional error message to be used if the value is required and missing.

  • preparer: Optional preparer for this node. It should be an object that implements the colander.interfaces.Preparer interface.

  • validator: Optional validator for this node. It should be an object that implements the colander.interfaces.Validator interface.

  • after_bind: A callback which is called after a clone of this node has ‘bound’ all of its values successfully. This callback is useful for performing arbitrary actions to the cloned node, or direct children of the cloned node (such as removing or adding children) at bind time. A ‘binding’ is the result of an execution of the bind method of the clone’s prototype node, or one of the parents of the clone’s prototype nodes. The deepest nodes in the node tree are bound first, so the after_bind methods of the deepest nodes are called before the shallowest. The after_bind callback should accept two values: node and kw. node will be a clone of the bound node object, kw will be the set of keywords passed to the bind method.

  • title: The title of this node. Defaults to a titleization of the name (underscores replaced with empty strings and the first letter of every resulting word capitalized). The title is used by higher-level systems (not by Colander itself).

  • description: The description for this node. Defaults to '' (the empty string). The description is used by higher-level systems (not by Colander itself).

  • widget: The ‘widget’ for this node. Defaults to None. The widget attribute is not interpreted by Colander itself, it is only meaningful to higher-level systems such as Deform.

  • insert_before: if supplied, it names a sibling defined by a superclass for its parent node; the current node will be inserted before the named node. It is not useful unless a mapping schema is inherited from another mapping schema, and you need to control the ordering of the resulting nodes.

Arbitrary keyword arguments remaining will be attached to the node object unmolested.

point_series
class gnome.utilities.graphs.graph.Labels(*args, **kw)

Bases: colander.SequenceSchema

Fundamental building block of schemas.

The constructor accepts these positional arguments:

  • typ: The ‘type’ for this node. It should be an instance of a class that implements the colander.interfaces.Type interface. If typ is not passed, a call to the schema_type() method on this class is made to get a default type. (When subclassing, schema_type() should be overridden to provide a reasonable default type).

  • *children: a sequence of subnodes. If the subnodes of this node are not known at construction time, they can later be added via the add method.

The constructor accepts these keyword arguments:

  • name: The name of this node.

  • typ: The ‘type’ for this node can optionally be passed in as a keyword argument. See the documentation for the positional arg above.

  • default: The default serialization value for this node when not set. If default is colander.drop, the node will be dropped from schema serialization. If not provided, the node will be serialized to colander.null.

  • missing: The default deserialization value for this node. If it is not provided, the missing value of this node will be the special marker value colander.required, indicating that it is considered ‘required’. When missing is colander.required, the required computed attribute will be True. When missing is colander.drop, the node is dropped from the schema if it isn’t set during deserialization.

  • missing_msg: Optional error message to be used if the value is required and missing.

  • preparer: Optional preparer for this node. It should be an object that implements the colander.interfaces.Preparer interface.

  • validator: Optional validator for this node. It should be an object that implements the colander.interfaces.Validator interface.

  • after_bind: A callback which is called after a clone of this node has ‘bound’ all of its values successfully. This callback is useful for performing arbitrary actions to the cloned node, or direct children of the cloned node (such as removing or adding children) at bind time. A ‘binding’ is the result of an execution of the bind method of the clone’s prototype node, or one of the parents of the clone’s prototype nodes. The deepest nodes in the node tree are bound first, so the after_bind methods of the deepest nodes are called before the shallowest. The after_bind callback should accept two values: node and kw. node will be a clone of the bound node object, kw will be the set of keywords passed to the bind method.

  • title: The title of this node. Defaults to a titleization of the name (underscores replaced with empty strings and the first letter of every resulting word capitalized). The title is used by higher-level systems (not by Colander itself).

  • description: The description for this node. Defaults to '' (the empty string). The description is used by higher-level systems (not by Colander itself).

  • widget: The ‘widget’ for this node. Defaults to None. The widget attribute is not interpreted by Colander itself, it is only meaningful to higher-level systems such as Deform.

  • insert_before: if supplied, it names a sibling defined by a superclass for its parent node; the current node will be inserted before the named node. It is not useful unless a mapping schema is inherited from another mapping schema, and you need to control the ordering of the resulting nodes.

Arbitrary keyword arguments remaining will be attached to the node object unmolested.

label
class gnome.utilities.graphs.graph.Formats(*args, **kw)

Bases: colander.SequenceSchema

Fundamental building block of schemas.

The constructor accepts these positional arguments:

  • typ: The ‘type’ for this node. It should be an instance of a class that implements the colander.interfaces.Type interface. If typ is not passed, a call to the schema_type() method on this class is made to get a default type. (When subclassing, schema_type() should be overridden to provide a reasonable default type).

  • *children: a sequence of subnodes. If the subnodes of this node are not known at construction time, they can later be added via the add method.

The constructor accepts these keyword arguments:

  • name: The name of this node.

  • typ: The ‘type’ for this node can optionally be passed in as a keyword argument. See the documentation for the positional arg above.

  • default: The default serialization value for this node when not set. If default is colander.drop, the node will be dropped from schema serialization. If not provided, the node will be serialized to colander.null.

  • missing: The default deserialization value for this node. If it is not provided, the missing value of this node will be the special marker value colander.required, indicating that it is considered ‘required’. When missing is colander.required, the required computed attribute will be True. When missing is colander.drop, the node is dropped from the schema if it isn’t set during deserialization.

  • missing_msg: Optional error message to be used if the value is required and missing.

  • preparer: Optional preparer for this node. It should be an object that implements the colander.interfaces.Preparer interface.

  • validator: Optional validator for this node. It should be an object that implements the colander.interfaces.Validator interface.

  • after_bind: A callback which is called after a clone of this node has ‘bound’ all of its values successfully. This callback is useful for performing arbitrary actions to the cloned node, or direct children of the cloned node (such as removing or adding children) at bind time. A ‘binding’ is the result of an execution of the bind method of the clone’s prototype node, or one of the parents of the clone’s prototype nodes. The deepest nodes in the node tree are bound first, so the after_bind methods of the deepest nodes are called before the shallowest. The after_bind callback should accept two values: node and kw. node will be a clone of the bound node object, kw will be the set of keywords passed to the bind method.

  • title: The title of this node. Defaults to a titleization of the name (underscores replaced with empty strings and the first letter of every resulting word capitalized). The title is used by higher-level systems (not by Colander itself).

  • description: The description for this node. Defaults to '' (the empty string). The description is used by higher-level systems (not by Colander itself).

  • widget: The ‘widget’ for this node. Defaults to None. The widget attribute is not interpreted by Colander itself, it is only meaningful to higher-level systems such as Deform.

  • insert_before: if supplied, it names a sibling defined by a superclass for its parent node; the current node will be inserted before the named node. It is not useful unless a mapping schema is inherited from another mapping schema, and you need to control the ordering of the resulting nodes.

Arbitrary keyword arguments remaining will be attached to the node object unmolested.

format
class gnome.utilities.graphs.graph.Graph(points, labels='', formats=None, title='Title', **kwargs)

Bases: gnome.gnomeobject.GnomeId

A class for assigning a unique ID for an object

Parameters:
  • points (Sequence of data point items in the form:: ((X1, X2, X3, ... XN), (S1(1), S1(2), S1(3), ... S1(N)) ... (SN(1), SN(2), SN(3), ... SN(N)) ) where the first item contains the X axis we will use, followed by 1 or more sequences of series data to be plotted on the Y axis.) – A sequence of data points for us to graph

  • labels – A list of labels to be used with our series data sets. If labels are not given, then we use default labels.

  • formats – An optional list of pyplot format strings to be used with our series data sets.

_schema
default_labels = 'XYZABCDEFGHJKLMNPQRSTUVW'
xaxis_plus_one_series = 2
__del__()

The entire python session could be shutting down at this point, so don’t assume anything exists externally to our object We will use the EAFP idiom here though.

render()
_init_figure()
  • opening the figure by fig_num will reuse any existing figure. So we will simply open the figure by number

  • It will probably be OK to just clear the figure every time.

_plot_points()
_get_styles(idx)
_get_label(idx)
_label_xaxis()
_label_yaxis()
_make_legend()
gnome.utilities.graphs.graph.dg