The graph module
A container for graphical data.
A Graph is an object to facilitate interactions between an Experiment
and an actual GUI implementation of graphing.
This module provides the following classes:
- Graph:
- An interface for passing data from an experiment to a visual graph.
- AbstractGraphManager:
- An interface for spawning graph threads; it (and all its methods) must be
overridden to actually see anything.
Classes
AbstractGraphManager
-
class src.core.graph.AbstractGraphManager(parentFrame)[source]
An abstract manager for graphs.
The purpose of a GraphManager is to take as input a list of Graph
objects and, as the experiment is preparing to run, create a frame or
frames to hold the graphical representation of the graphs and start
threads to update them as data become available.
Parameters : | parentFrame :
A GUI frame to pass as the parent of each graph frame.
|
Methods
-
abort(timeout=10.0)[source]
Stop graphing.
Command all Graph objects to stop taking new data.
Parameters : | timeout : float
The maximum time to wait for the threads to join.
|
-
saveGraphs(filename)[source]
Save the graphs to a file or files.
Parameters : | filename : str or list
The output file(s) to which the graph(s) should be saved.
Implementations may require either a string or a list of strings.
|
-
setGraphs(graphs)[source]
Set the graphs to be managed.
Parameters : | graphs : list of Graph
|
-
start()[source]
Start graphing.
Start a thread for each Graph object. These should be spawned as
‘daemon’ threads, so that if the program is exited, the threads all
stop.
Graph
-
class src.core.graph.Graph(experiment, colX, colY, colAdd)[source]
A Graph is an object for managing interactions between an
Experiment and some graphical interface for actually displaying the
data. It effects the data transfer by pushing data points onto a Queue
object.
Parameters : | experiment : Experiment
The Experiment object which owns this Graph.
colx : str
The name of the column from which the x coordinates come.
coly : str
The name of the column from which the y coordinates come.
colAdd : str
The name of the column which, when updated, should signal that the next
point added to the graph should begin a new plot.
|
Notes
The Graph object does not actually store all of the data—it only keeps
track of the latest point. The reason is that nearly every GUI
implementation of graphing needs to keep track of all of the data, so
Graph and the graphing panel/frame contain it would double the
memory used with no real advantage.
Methods
-
addX(newx)[source]
Add the x-coordinate of the next point to the graph.
Parameters : | newx : float
The new x-value to add to the graph. If it is an integer or a
string, it will be coerced to a float.
|
-
addY(newy)[source]
Add the y-coordinate of the next point to the graph.
Parameters : | newy : float
The new y-value to add to the graph. If it is an integer or a
string, it will be coerced to a float.
|
-
checkPoint()[source]
Add a point to the graph, if appropriate.
Check whether there is both an x- and a y-coordinate available. If so,
add a tuple to the queue, where the tuple contains the following
elements in order:
- New x-coordinate
- New y-coordinate
- Minimum x-coordinate for the graph
- Maximum x-coordinate for the graph
- Minimum y-coordinate for the graph
- Maximum y-coordinate for the graph
- Whether this point goes into a new plot
Then reset the graph’s fields.
-
clear()[source]
Reset the graph data.
-
flagNewPlot()[source]
Indicate that the next point should go into a new plot.
-
getColumns()[source]
Return the column names which will provide data to this graph.
Returns : | tuple of str :
A 3-tuple whose contents are, in order, the names of the x data
column, the y data column, and the column to trigger new plots on
the graph.
|
-
getTitle()[source]
Get the title of the graph (“y name vs. x name”).
Returns : | str :
The name of the graph, in the form “y-column name vs. x-column
name”.
|
-
getXML(indent=0)[source]
Return an XML string representing the graph.
Returns : | str :
A string containing XML data representing all of the data related
to the graph, possibly useful as an alternative to pickle.
|
-
isEnabled()[source]
Return whether the graph is enabled.
The enabled state determines only whether or not the experiment adds
it to the manager. The Graph object itself does not use the flag at
all.
Returns : | bool :
Whether the graph is enabled.
|
-
setColumns(cols)[source]
Set the names of the columns which will provide data to this graph.
Parameters : | cols : tuple of str
A 3-tuple whose contents indicate the names of the x-column, the
y-column, and the column which should trigger new plots on the
graph, in that order.
|
-
setDataQueue(queue)[source]
Set the queue to pass data to the UI.
A queue is used to pass data from this graph object to the graphical
component which actually displays the data.
Parameters : | queue : Queue.Queue
The queue to pass data to the user interface.
|
-
setEnabled(enabled)[source]
Set whether this graph is enabled.
The enabled state determines only whether or not the experiment adds
it to the manager. The Graph object itself does not use the flag at
all.
Parameters : | enabled : bool
Whether the graph should be enabled.
|
-
updateColumnsIfNecessary(oldcol, newcol)[source]
Update graph labels to reflect changes in column names.
Parameters : | oldcol : str
The name of the column from which the graph previously received
data.
newcol : str
The name of the column from which the graph should now receive
data.
|