fsleyes.views.plotpanel
¶
This module provides the PlotPanel
and OverlayPlotPanel
classes. The PlotPanel
class is the base class for all FSLeyes views
which display some sort of data plot. The OverlayPlotPanel
is a
PlotPanel
which contains some extra logic for displaying plots related to
the currently selected overlay.
The actual plotting logic (using matplotilb
) is implemented within the
PlotCanvas
class.
- class fsleyes.views.plotpanel.PlotPanel(parent, overlayList, displayCtx, frame)[source]¶
Bases:
fsleyes.views.viewpanel.ViewPanel
The
PlotPanel
class is the base class for all FSLeyes views which display some sort of 2D data plot, such as theTimeSeriesPanel
, and theHistogramPanel
.Note
See also the
OverlayPlotPanel
, which contains extra logic for displaying plots related to the currently selected overlay, and which is the actual base class used by theTimeSeriesPanel
,HistogramPanel
andPowerSpectrumPanel
.PlotPanel
uses aPlotCanvas
, which in turn uses :mod`:matplotlib` for its plotting. ThePlotCanvas
instance used by aPlotPanel
can be accessed via thecanvas()
method, which in turn can be used to manipulate the plot display settings. Thematplotlib
Figure
,Axis
, andCanvas
instances can be accessed via thePlotCanvas
instance, if they are needed.Sub-class requirements
Sub-class implementations of
PlotPanel
must do the following:Call the
PlotPanel
constructor.Define one or more
DataSeries
sub-classes if needed.Override the
draw()
method, so it calls thePlotCanvas.drawDataSeries()
andPlotCanvas.drawArtists()
methods (draw()
is passed to thePlotCanvas
as a customdrawFunc
).If necessary, override the
prepareDataSeries()
method to perform any preprocessing onextraSeries
passed to thedrawDataSeries()
method (but not applied toDataSeries
that have been added to thedataSeries
list) (prepareDataSeries()
is passed to thePlotCanvas
as a customprepareFunc
).If necessary, override the
destroy()
method, but make sure that the base-class implementation is called.
Plot panel actions
A number of
actions
are also provided by thePlotPanel
class:Prompts the user to select a file name, then saves a screenshot of the current plot.
Imports data series from a text file.
Exports displayed data series to a text file.
- controlOptions(cpType)[source]¶
Returns some options to be used by
ViewPanel.togglePanel()
for certain control panel types.
- __init__(parent, overlayList, displayCtx, frame)[source]¶
Create a
PlotPanel
.- Parameters
parent – The
wx
parent object.overlayList – An
OverlayList
instance.displayCtx – A
DisplayContext
instance.frame – The
FSLeyesFrame
instance.
- destroy()[source]¶
Removes some property listeners, and then calls
ViewPanel.destroy()
.
- property canvas¶
Returns a reference to the
PlotCanvas
.
- draw(*a)[source]¶
This method must be overridden by
PlotPanel
sub-classes. Sub-class implementations should call thedrawDataSeries()
and meth:drawArtists methods.
- prepareDataSeries(ds)[source]¶
Prepares the data from the given
DataSeries
so it is ready to be plotted. Called by the__drawOneDataSeries()
method for anyextraSeries
passed to thedrawDataSeries()
method (but not applied toDataSeries
that have been added to thedataSeries
list).This implementation just returns
DataSeries.getData
- override it to perform any custom preprocessing.
- screenshot(*a)[source]¶
Prompts the user to select a file name, then saves a screenshot of the current plot.
See the
ScreenshotAction
.
- importDataSeries(*a)[source]¶
Imports data series from a text file.
See the
ImportDataSeriesAction
.
- exportDataSeries(*args, **kwargs)[source]¶
Exports displayed data series to a text file.
See the
ExportDataSeriesAction
.
- __annotations__ = {}¶
- __module__ = 'fsleyes.views.plotpanel'¶
- class fsleyes.views.plotpanel.OverlayPlotPanel(*args, **kwargs)[source]¶
Bases:
fsleyes.views.plotpanel.PlotPanel
The
OverlayPlotPanel
is aPlotPanel
which contains some extra logic for creating, storing, and drawingDataSeries
instances for each overlay in theOverlayList
.Subclass requirements
Sub-classes must:
Implement the
createDataSeries()
method, so it creates aDataSeries
instance for a specified overlay.Implement the
PlotPanel.draw()
method so it calls thePlotCanvas.drawDataSeries()
, passingDataSeries
instances for all overlays whereDisplay.enabled
isTrue
, and the callPlotCanvas.drawArtists()
method.Optionally implement the
prepareDataSeries()
method to perform any custom preprocessing.
The internal data series store
The
OverlayPlotPanel
maintains a store ofDataSeries
instances, one for each compatible overlay in theOverlayList
. TheOverlayPlotPanel
manages the property listeners that must be registered with each of theseDataSeries
to refresh the plot. These instances are created by thecreateDataSeries()
method, which is implemented by sub-classes. The following methods are available to sub-classes, for managing the internal store ofDataSeries
instances:Returns the
DataSeries
instance associated with the specified overlay, orNone
if there is noDataSeries
instance.Convenience method which returns a list of overlays which have
DataSeries
that should be plotted.Destroys the internally cached
DataSeries
for the given overlay.Makes sure that a
DataSeries
instance has been created for every compatible overlay, and that property listeners are correctly registered, so the plot can be refreshed when needed.Every
DataSeries
which is currently plotted, and has not been added to thePlotCanvas.dataSeries
list, is added to said list.Removes the most recently added
DataSeries
from thePlotCanvas.dataSeries
.Proxy images
The
OverlayPlotPanel
will replace allProxyImage
instances with their base images. This functionality was originally added to support theHistogramSeries.showOverlay
functionality - it adds a mask image to theOverlayList
to display the histogram range. Sub-classes may wish to adhere to the same logic (replacingProxyImage
instances with their bases)Control panels
The
PlotControlPanel
,PlotListPanel
, andOverlayListPanel
are FSLeyes control panels which work with theOverlayPlotPanel
. ThePlotControlPanel
is not intended to be used directly - view-specific sub-classes are used instead. These panels can be added/removed via theViewPanel.togglePanel()
method.Sub-classes
The
OverlayPlotPanel
is the base class for:The
TimeSeriesPanel
is anOverlayPlotPanel
which plots time series data from overlays.An
OverlayPlotPanel
which plots histograms fromImage
overlay data.The
PowerSpectrumPanel
class is anOverlayPlotPanel
which plots power spectra of overlay data.- plotColours = {}¶
This dictionary is used to store a collection of
{overlay : colour}
mappings. It is shared across allOverlayPlotPanel
instances, so that the same (initial) colour is used for the same overlay, across multiple plots.See also
plotStyles
.Sub-classes should use the
getOverlayPlotColour()
andgetOverlayPlotStyle()
methods to retrieve the initial colour and linestyle to use for a given overlay.
- plotStyles = {}¶
This dictionary is used to store a collection of
{overlay : colour}
mappings - it is used in conjunction withplotColours
.
- __init__(*args, **kwargs)[source]¶
Create an
OverlayPlotPanel
.- Parameters
initialState – Must be passed as a keyword argument. Allows you to specify the initial enabled/disabled state for each overlay. See
updateDataSeries()
. If not provided, only the data series for the currently selected overlay is shown (if possible).
All other argumenst are passed through to
PlotPanel.__init__()
.
- destroy()[source]¶
Must be called when this
OverlayPlotPanel
is no longer needed. Removes some property listeners, and callsPlotPanel.destroy()
.
- getDataSeriesToPlot()[source]¶
Convenience method which returns a list of overlays which have
DataSeries
that should be plotted.
- getDataSeries(overlay)[source]¶
Returns the
DataSeries
instance associated with the specified overlay, orNone
if there is noDataSeries
instance.
- getOverlayPlotColour(overlay)[source]¶
Returns an initial colour to use for plots associated with the given overlay. If a colour is present in the
plotColours
dictionary, it is returned. Otherwise a random colour is generated, added toplotColours
, and returned.
- getOverlayPlotStyle(overlay)[source]¶
Returns an initial line style to use for plots associated with the given overlay. If a colour is present in the
plotStyles
dictionary, it is returned. Otherwise a line style is generated, added toplotStyles
, and returned.The format of the returned line style is suitable for use with the
linestyle
argument of thematplotlib
plot
functions.
- addDataSeries()[source]¶
Every
DataSeries
which is currently plotted, and has not been added to thePlotCanvas.dataSeries
list, is added to said list.
- removeDataSeries(*a)[source]¶
Removes the most recently added
DataSeries
from thePlotCanvas.dataSeries
.
- createDataSeries(overlay)[source]¶
This method must be implemented by sub-classes. It must create and return a
DataSeries
instance for the specified overlay.Note
Sub-class implementations should set the
DataSeries.colour
property to that returned by thegetOverlayPlotColour()
method, and theDataSeries.lineStyle
property to that returned by thegetOverlayPlotStyle()
methodDifferent
DataSeries
types need to be re-drawn when different properties change. For example, aVoxelTimeSeries`
instance needs to be redrawn when theDisplayContext.location
property changes, whereas aMelodicTimeSeries
instance needs to be redrawn when theVolumeOpts.volume
property changes.Therefore, in addition to creating and returning a
DataSeries
instance for the given overlay, sub-class implementations must also specify the properties which affect the state of theDataSeries
instance. These must be specified as two lists:the targets list, a list of objects which own the dependant properties (e.g. the
DisplayContext
orVolumeOpts
instance).The properties list, a list of names, each specifying the property on the corresponding target.
This method must therefore return a tuple containing:
A
DataSeries
instance, orNone
if the overlay is incompatible.A list of target instances.
A list of property names.
The target and property name lists must have the same length.
- clearDataSeries(overlay)[source]¶
Destroys the internally cached
DataSeries
for the given overlay.
- updateDataSeries(initialState=None)[source]¶
Makes sure that a
DataSeries
instance has been created for every compatible overlay, and that property listeners are correctly registered, so the plot can be refreshed when needed.- Parameters
initialState – If provided, must be a
dict
of{ overlay : bool }
mappings, specifying the initial value of theDataSeries.enabled
property for newly created instances. If not provided, only the data series for the currently selected overlay (if it has been newly added) is initially enabled.
- __dataSeriesChanged(*a)¶
Called when the
PlotCanvas.dataSeries
list changes. Enables/disables theremoveDataSeries()
action accordingly.
- __annotations__ = {}¶
- __module__ = 'fsleyes.views.plotpanel'¶
- __overlayListChanged(*a, **kwa)¶
Called when the
OverlayList
changes. Makes sure that there are noDataSeries
instances in thePlotCanvas.dataSeries
list, or in the internal cache, which refer to overlays that no longer exist.- Parameters
initialState – Must be passed as a keyword argument. If provided, passed through to the
updateDataSeries()
method.