The plotters module plotter backends¶
The plotters module contains classes for easy plotting of data.
The data logger¶
The DataLogger
is a general purpose plotter that is suitable
for plotting data sets as they are being gathered. The data logger
uses the qwt backend, though the class QwtPlot
, that forms
the plot by means of the PyQwt library.
Usage Example¶
import sys
import time
import random
import numpy as np
from PyQt4 import Qt, QtGui, QtCore
from PyExpLabSys.common.plotters import DataPlotter
class TestApp(QtGui.QWidget):
"""Test Qt application"""
def __init__(self):
super(TestApp, self).__init__()
# Form plotnames
self.plots_l = ['signal1', 'signal2']
self.plots_r = ['aux_signal1']
self.plotter = DataPlotter(
self.plots_l, right_plotlist=self.plots_r, parent=self,
left_log=True, title='Awesome plots',
yaxis_left_label='Log sine, cos', yaxis_right_label='Noisy line',
xaxis_label='Time since start [s]',
legend='right', left_thickness=[2, 8], right_thickness=6,
left_colors=['firebrick', 'darkolivegreen'],
right_colors=['darksalmon'])
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.plotter.plot)
self.setLayout(hbox)
self.setGeometry(5, 5, 500, 500)
self.start = time.time()
QtCore.QTimer.singleShot(10, self.main)
def main(self):
"""Simulate gathering one set of points and adding them to plot"""
elapsed = time.time() - self.start
value = (np.sin(elapsed) + 1.1) * 1E-9
self.plotter.add_point('signal1', (elapsed, value))
value = (np.cos(elapsed) + 1.1) * 1E-8
self.plotter.add_point('signal2', (elapsed, value))
value = elapsed + random.random()
self.plotter.add_point('aux_signal1', (elapsed, value))
QtCore.QTimer.singleShot(100, self.main)
def main():
"""Main method"""
app = Qt.QApplication(sys.argv)
testapp = TestApp()
testapp.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
plotters module¶
This module contains plotters for experimental data gathering applications. It contains a plotter for data sets.
-
class
PyExpLabSys.common.plotters.
DataPlotter
(left_plotlist, right_plotlist=None, left_log=False, right_log=False, auto_update=True, backend='qwt', parent=None, **kwargs)[source]¶ Bases:
object
This class provides a data plotter for continuous data
-
__init__
(left_plotlist, right_plotlist=None, left_log=False, right_log=False, auto_update=True, backend='qwt', parent=None, **kwargs)[source]¶ Initialize the plotting backend, data and local setting
Parameters: - left_plotlist (iterable with strs) – Codenames for the plots that should go on the left y-axis
- right_plotlist – Codenames for the plots that should go in the right y-axis
- left_log (bool) – Left y-axis should be log
- right_log (bool) – Right y-axis should be log
- auto_update (bool) – Whether all data actions should trigger an update
- backend (str) – The plotting backend to use. Current only option is ‘qwt’
- parent (GUI object) – If a GUI backend is used that needs to know the parent GUI object, then that should be supplied here
Kwargs:
Parameters: - title (str) – The title of the plot
- xaxis_label (str) – Label for the x axis
- yaxis_left_label (str) – Label for the left y axis
- yaxis_right_label (str) – Label for the right y axis
- left_labels (iterable with strs) – Labels for the plots on the left y-axis. If none are given the codenames will be used.
- right_labels (iterable with strs) – Labels for the plots on the right y-axis. If none are given the codenames will be used.
- legend (str) – Position of the legend. Possible values are: ‘left’, ‘right’, ‘bottom’, ‘top’. If no argument is given, the legend will not be shown.
- left_colors (iterable of strs) – Colors for the left curves (see background_color for details)
- right_colors (iterable of strs) – Colors for the right curves (see background_color for details)
- left_thickness (int or iterable of ints) – Line thickness. Either an integer to apply for all left lines or a iterable of integers, one for each line.
- right_thickness (int or iterable of ints) – Line thickness. Either an integer to apply for all right lines or a iterable of integers, one for each line.
- background_color (str) – The name in a str (as understood by QtGui.QColor(), see Colors section for possible values) or a string with a hex value e.g. ‘#101010’ that should be used as the background color.
-
add_point
(plot, point, update=None)[source]¶ Add a point to a plot
Parameters: - plot (str) – The codename for the plot
- point (Iterable with x and y value as two numpy.float) – The point to add
- update – Whether a update should be performed after adding the
point. If set, this value will over write the
auto_update
value
Returns: plot content or None
-
data
¶ Get and set the data
-
plot
¶ Get the plot
-
-
class
PyExpLabSys.common.plotters.
ContinuousPlotter
(left_plotlist, right_plotlist=None, left_log=False, right_log=False, timespan=600, preload=60, auto_update=True, backend='none', **kwargs)[source]¶ Bases:
object
This class provides a data plotter for continuous data
-
__init__
(left_plotlist, right_plotlist=None, left_log=False, right_log=False, timespan=600, preload=60, auto_update=True, backend='none', **kwargs)[source]¶ Initialize the plotting backend, data and local setting
Parameters: - left_plotlist (iterable with strs) – Codenames for the plots that should go on the left y-axis
- right_plotlist – Codenames for the plots that should go in the right y-axis
- left_log (bool) – Left y-axis should be log
- right_log (bool) – Right y-axis should be log
- timespan (int) – Numbers of seconds to show in the plot
- preload (int) – Number of seconds to jump ahead when reaching edge of plot
- auto_update (bool) – Whether all data actions should trigger a update
- backend (str) – The plotting backend to use. Current only option is ‘none’
Kwargs
TODO
-
add_point_now
(plot, value, update=None)[source]¶ Add a point to a plot using now as the time
Parameters: - plot (str) – The codename for the plot
- value (numpy.float) – The value to add
- update – Whether a update should be performed after adding the
point. If set, this value will over write the
auto_update
value
Returns: plot content or None
-
add_point
(plot, point, update=None)[source]¶ Add a point to a plot
Parameters: - plot (str) – The codename for the plot
- point (Iterable with unix time and value as two numpy.float) – The point to add
- update – Whether a update should be performed after adding the
point. If set, this value will over write the
auto_update
value
Returns: plot content or None
-
data
¶ Get and set the data
-
plot
¶ Get the plot
-
The qwt backend¶
plotters_backend_qwt¶
This module contains plotting backends that use the PyQwt library
-
class
PyExpLabSys.common.plotters_backend_qwt.
Colors
[source]¶ Bases:
object
Class that gives plot colors
-
class
PyExpLabSys.common.plotters_backend_qwt.
QwtPlot
(parent, left_plotlist, right_plotlist=None, left_log=False, right_log=False, **kwargs)[source]¶ Bases:
list
Class that represents a Qwt plot
-
__init__
(parent, left_plotlist, right_plotlist=None, left_log=False, right_log=False, **kwargs)[source]¶ Initialize the plot and local setting
Parameters: - parent (GUI object) – The parent GUI object, then that should be supplied here
- left_plotlist (iterable with strs) – Codenames for the plots that should go on the left y-axis
- right_plotlist – Codenames for the plots that should go in the right y-axis
- left_log (bool) – Left y-axis should be log
- right_log (bool) – Right y-axis should be log
Kwargs:
Parameters: - title (str) – The title of the plot
- xaxis_label (str) – Label for the x axis
- yaxis_left_label (str) – Label for the left y axis
- yaxis_right_label (str) – Label for the right y axis
- left_labels (iterable with strs) – Labels for the plots on the left y-axis. If none are given the codenames will be used.
- right_labels (iterable with strs) – Labels for the plots on the right y-axis. If none are given the codenames will be used.
- legend (str) – Position of the legend. Possible values are: ‘left’, ‘right’, ‘bottom’, ‘top’. If no argument is given, the legend will not be shown.
- left_colors (iterable of strs) – Colors for the left curves (see background_color for details)
- right_colors (iterable of strs) – Colors for the right curves (see background_color for details)
- left_thickness (int or iterable of ints) – Line thickness. Either an integer to apply for all left lines or a iterable of integers, one for each line.
- right_thickness (int or iterable of ints) – Line thickness. Either an integer to apply for all right lines or a iterable of integers, one for each line.
- background_color (str) – The name in a str (as understood by QtGui.QColor(), see Colors section for possible values) or a string with a hex value e.g. ‘#101010’ that should be used as the background color.
-
Colors¶
aliceblue | antiquewhite | aqua | aquamarine |
azure | beige | bisque | black |
blanchedalmond | blue | blueviolet | brown |
burlywood | cadetblue | chartreuse | chocolate |
coral | cornflowerblue | cornsilk | crimson |
cyan | darkblue | darkcyan | darkgoldenrod |
darkgray | darkgreen | darkgrey | darkkhaki |
darkmagenta | darkolivegreen | darkorange | darkorchid |
darkred | darksalmon | darkseagreen | darkslateblue |
darkslategray | darkslategrey | darkturquoise | darkviolet |
deeppink | deepskyblue | dimgray | dimgrey |
dodgerblue | firebrick | floralwhite | forestgreen |
fuchsia | gainsboro | ghostwhite | gold |
goldenrod | gray | green | greenyellow |
grey | honeydew | hotpink | indianred |
indigo | ivory | khaki | lavender |
lavenderblush | lawngreen | lemonchiffon | lightblue |
lightcoral | lightcyan | lightgoldenrodyellow | lightgray |
lightgreen | lightgrey | lightpink | lightsalmon |
lightseagreen | lightskyblue | lightslategray | lightslategrey |
lightsteelblue | lightyellow | lime | limegreen |
linen | magenta | maroon | mediumaquamarine |
mediumblue | mediumorchid | mediumpurple | mediumseagreen |
mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred |
midnightblue | mintcream | mistyrose | moccasin |
navajowhite | navy | oldlace | olive |
olivedrab | orange | orangered | orchid |
palegoldenrod | palegreen | paleturquoise | palevioletred |
papayawhip | peachpuff | peru | pink |
plum | powderblue | purple | red |
rosybrown | royalblue | saddlebrown | salmon |
sandybrown | seagreen | seashell | sienna |
silver | skyblue | slateblue | slategray |
slategrey | snow | springgreen | steelblue |
tan | teal | thistle | tomato |
transparent | turquoise | violet | wheat |
white | whitesmoke | yellow | yellowgreen |