slim.gui_utils.plots module

This module provides plotting widgets and utils.

class slim.gui_utils.plots.LightModeMixin

Bases: object

property paperMode
setPaperMode(lightMode: bool)
class slim.gui_utils.plots.OptimiserPlotPane(mainPane: Window)

Bases: PyQt5.QtWidgets.QWidget, slim.gui_utils.plots.LightModeMixin

class slim.gui_utils.plots.ScientificAxisItem(orientation, pen=None, textPen=None, linkView=None, parent=None, maxTickLength=- 5, showValues=True, text='', units='', unitPrefix='', **args)

Bases: pyqtgraph.graphicsItems.AxisItem.AxisItem

A non-scientific axis. See <https://stackoverflow.com/a/43782129>_

Arguments:

orientation

one of ‘left’, ‘right’, ‘top’, or ‘bottom’

maxTickLength

(px) maximum length of ticks to draw. Negative values draw into the plot, positive values draw outward.

linkView

(ViewBox) causes the range of values displayed in the axis to be linked to the visible range of a ViewBox.

showValues

(bool) Whether to display values adjacent to ticks

pen

(QPen) Pen used when drawing ticks.

textPen

(QPen) Pen used when drawing tick labels.

text

The text (excluding units) to display on the label for this axis.

units

The units for this axis. Units should generally be given without any scaling prefix (eg, ‘V’ instead of ‘mV’). The scaling prefix will be automatically prepended based on the range of data displayed.

args

All extra keyword arguments become CSS style options for the <span> tag which will surround the axis label and units.

tickStrings(values, scale, spacing)

Return the strings that should be placed next to ticks. This method is called when redrawing the axis and is a good method to override in subclasses. The method is called with a list of tick values, a scaling factor (see below), and the spacing between ticks (this is required since, in some instances, there may be only one tick and thus no other way to determine the tick spacing)

The scale argument is used when the axis label is displaying units which may have an SI scaling prefix. When determining the text to display, use value*scale to correctly account for this prefix. For example, if the axis label’s units are set to ‘V’, then a tick value of 0.001 might be accompanied by a scale value of 1000. This indicates that the label is displaying ‘mV’, and thus the tick should display 0.001 * 1000 = 1.

class slim.gui_utils.plots.SingleRunPlotPane(mainPane: Window)

Bases: slim.gui_utils.plots.LightModeMixin, PyQt5.QtWidgets.QWidget

Main visualisation pane for the plots

cleanPlot()
exportPlots()

Export all the plots. This will open a dialog window asking for a directory where to save the images.

The images are saved in both PNG and SVG format. The resolution depends on the window resolution. (To get greater control on plot resolution I’m afraid we need to export to matplotlib?)

This will generate the following:

  • An image of the whole scene, called “{sim_id}_all”

  • An image for each plot, called “{sim_id}_{plot_type}_{i}”, e.g. “Fyne_150_lice_2”

setGenotype(value: bool)
property showGenotype
class slim.gui_utils.plots.SmoothedGraphicsLayoutWidget(parent: SingleRunPlotPane)

Bases: pyqtgraph.widgets.GraphicsLayoutWidget.GraphicsLayoutWidget

A wrapper for a GraphicsLayoutWidget that supports smoothing.

Arguments:

parent

Optional parent widget

useOpenGL

If True, the GraphicsView will use OpenGL to do all of its rendering. This can improve performance on some systems, but may also introduce bugs (the combination of QGraphicsView and QOpenGLWidget is still an ‘experimental’ feature of Qt)

background

Set the background color of the GraphicsView. Accepts any single argument accepted by mkColor. By default, the background color is determined using the ‘backgroundColor’ configuration option (see setConfigOptions).

addSmoothedPlot(exclude_from_averaging=False, force_scientific=False, **kwargs) SmoothedPlotItemWrap
clearPlots()
deleteLater(self)
disconnectAll()
enforceAspectRatio()
newAverageFactor
newKernelSize
setDefaultXAxis(timestamps: List[datetime.datetime])

Set the x-axis of all the plots

class slim.gui_utils.plots.SmoothedPlotItemWrap(plot_item: pyqtgraph.graphicsItems.PlotItem.PlotItem.PlotItem, smoothing_size: int, average_factor: int, method='linear')

Bases: object

A replacement for PlotItem that also implements convolution and averaging

Parameters
  • plot_item – the wrapped PlotItem

  • smoothing_size – the amount of smoothing to apply

  • average_factor – the common divider across lines (used when comparing farms with different cage numbers)

  • method – if to use linear smoothing. Currently, it is the only one supported.

color_palette = ['#d60000', '#018700', '#b500ff', '#05acc6', '#97ff00', '#ffa52f', '#ff8ec8', '#79525e', '#00fdcf', '#afa5ff', '#93ac83', '#9a6900', '#366962', '#d3008c', '#fdf490', '#c86e66', '#9ee2ff', '#00c846', '#a877ac', '#b8ba01', '#f4bfb1', '#ff28fd', '#f2cdff', '#009e7c', '#ff6200', '#56642a', '#953f1f', '#90318e', '#ff3464', '#a0e491', '#8c9ab1', '#829026', '#ae083f', '#77c6ba', '#bc9157', '#e48eff', '#72b8ff', '#c6a5c1', '#ff9070', '#d3c37c', '#bceddb', '#6b8567', '#916e56', '#f9ff00', '#bac1df', '#ac567c', '#ffcd03', '#ff49b1', '#c15603', '#5d8c90', '#c144bc', '#00753f', '#ba6efd', '#00d493', '#00ff75', '#49a150', '#cc9790', '#00ebed', '#db7e01', '#f77589', '#b89500', '#c84248', '#00cff9', '#755726', '#85d401', '#ebffd4', '#a77b87', '#db72c8', '#cae256', '#8abf5d', '#a1216b', '#855b89', '#89bacf', '#ffbad6', '#b6cfaa', '#97414d', '#67aa00', '#fde1b1', '#ff3628', '#80793d', '#d6e8ff', '#a795c6', '#7ea59a', '#d182a3', '#54823b', '#e6a872', '#9cffff', '#da5480', '#05b3aa', '#ffaaf6', '#d1afef', '#da015d', '#ac1a13', '#60b385', '#d442fd', '#acaa59', '#fb9ca7', '#b3723b', '#f26952', '#aed1d4', '#9affc3', '#dbb333', '#eb01c3', '#9900c4', '#cfff9e', '#a55949', '#3b6d01', '#008579', '#959167', '#89dbb3', '#6d7400', '#aa5dca', '#07ef00', '#804f3d', '#d88052', '#ffc862', '#b8009e', '#99acdd', '#904f00', '#8c4470', '#4f6e52', '#ff8734', '#c68ecd', '#d4e29e', '#b1826d', '#9cfb75', '#56dd77', '#f90087', '#a1cdff', '#13cad1', '#118e54', '#d154a5', '#00dfc3', '#a3832f', '#77975b', '#baaa80', '#70a3af', '#d6fbff', '#e8013a', '#d84621', '#ff82ed', '#b63862', '#b6cd72', '#97626b', '#897490', '#00a316', '#00f4a1', '#bf90f2', '#89e4d8', '#a34d95', '#6e5d00', '#8cc68e', '#95aa2a', '#c672dd', '#b33b01', '#d69a36', '#dfacb6', '#009aa0', '#599000', '#97bca8', '#ac8ca8', '#dad4ff', '#547c72', '#00ba69', '#ffc38e', '#b800d4', '#dfcf5b', '#629a7b', '#bfedbc', '#c1bdfd', '#80d3dd', '#e2857e', '#f9eb4d', '#bf6d82', '#caff4f', '#ef72aa', '#ed67ff', '#9946ae', '#6d6942', '#e25660', '#dd662d', '#9cdb5d', '#e29ccf', '#b87500', '#c6002d', '#dfbcda', '#59b5df', '#ff59da', '#38c1a1', '#9e698c', '#acaac8', '#95622f', '#b55662', '#2b7e60', '#b1e400', '#eda590', '#95fde2', '#ff548e', '#bd6ea1', '#aa3b36', '#d8cf00', '#aa80cd', '#a08052', '#e100e8', '#c35b3d', '#b53a85', '#8c7700', '#dbbc95', '#529e93', '#afbc82', '#91b5b6', '#a75423', '#ffd4ef', '#79ae6b', '#5db54b', '#80fb9a', '#48ffef', '#979548', '#9387a7', '#31d400', '#6ee956', '#b6d4eb', '#705470', '#f2db8a', '#aad4c1', '#7ecdf2', '#89ba00', '#64b6ba', '#ffb500', '#c38285', '#caaa5e', '#647748', '#59e2ff', '#df4dcd', '#e9ff79', '#bc66b8', '#c395a5', '#64c674', '#d19570', '#70cf4f', '#aa6e66', '#9c60a5', '#00b800', '#e299b3', '#bc006b', '#b3e8ef', '#cdbfe4', '#77a342', '#856277', '#568e5b', '#9eafc4', '#e82fa0', '#247c2a', '#826723', '#bfbc4d', '#ddd3a5']
heightForWidth(width)
plot(y, stage: Optional[str] = None, x: Optional[List[datetime.datetime]] = None, **kwargs) pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

Plot a list of values

For a list of options check pg.PlotdataItem.__init__()

Parameters
  • y – the sequence to plot

  • stage – if y is a population, pick a selected lifecycle stage

  • x – provide an optional x-axis

setAverageFactor(average_factor: int)
setSmoothingFactor(kernel_size: int)
setXAxis(timestamps: List[datetime.datetime])