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.ViewPanelThe
PlotPanelclass 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,HistogramPanelandPowerSpectrumPanel.PlotPaneluses aPlotCanvas, which in turn uses :mod`:matplotlib` for its plotting. ThePlotCanvasinstance used by aPlotPanelcan be accessed via thecanvas()method, which in turn can be used to manipulate the plot display settings. ThematplotlibFigure,Axis, andCanvasinstances can be accessed via thePlotCanvasinstance, if they are needed.Sub-class requirements
Sub-class implementations of
PlotPanelmust do the following:Call the
PlotPanelconstructor.Define one or more
DataSeriessub-classes if needed.Override the
draw()method, so it calls thePlotCanvas.drawDataSeries()andPlotCanvas.drawArtists()methods (draw()is passed to thePlotCanvasas a customdrawFunc).If necessary, override the
prepareDataSeries()method to perform any preprocessing onextraSeriespassed to thedrawDataSeries()method (but not applied toDataSeriesthat have been added to thedataSerieslist) (prepareDataSeries()is passed to thePlotCanvasas a customprepareFunc).If necessary, override the
destroy()method, but make sure that the base-class implementation is called.
Plot panel actions
A number of
actionsare also provided by thePlotPanelclass: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
wxparent object.overlayList – An
OverlayListinstance.displayCtx – A
DisplayContextinstance.frame – The
FSLeyesFrameinstance.
-
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
PlotPanelsub-classes. Sub-class implementations should call thedrawDataSeries()and meth:drawArtists methods.
-
prepareDataSeries(ds)[source]¶ Prepares the data from the given
DataSeriesso it is ready to be plotted. Called by the__drawOneDataSeries()method for anyextraSeriespassed to thedrawDataSeries()method (but not applied toDataSeriesthat have been added to thedataSerieslist).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.
-
__module__= 'fsleyes.views.plotpanel'¶
-
class
fsleyes.views.plotpanel.OverlayPlotPanel(*args, **kwargs)[source]¶ Bases:
fsleyes.views.plotpanel.PlotPanelThe
OverlayPlotPanelis aPlotPanelwhich contains some extra logic for creating, storing, and drawingDataSeriesinstances for each overlay in theOverlayList.Subclass requirements
Sub-classes must:
Implement the
createDataSeries()method, so it creates aDataSeriesinstance for a specified overlay.Implement the
PlotPanel.draw()method so it calls thePlotCanvas.drawDataSeries(), passingDataSeriesinstances for all overlays whereDisplay.enabledisTrue, and the callPlotCanvas.drawArtists()method.Optionally implement the
prepareDataSeries()method to perform any custom preprocessing.
The internal data series store
The
OverlayPlotPanelmaintains a store ofDataSeriesinstances, one for each compatible overlay in theOverlayList. TheOverlayPlotPanelmanages the property listeners that must be registered with each of theseDataSeriesto 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 ofDataSeriesinstances:Returns the
DataSeriesinstance associated with the specified overlay, orNoneif there is noDataSeriesinstance.Convenience method which returns a list of overlays which have
DataSeriesthat should be plotted.Destroys the internally cached
DataSeriesfor the given overlay.Makes sure that a
DataSeriesinstance has been created for every compatible overlay, and that property listeners are correctly registered, so the plot can be refreshed when needed.Every
DataSerieswhich is currently plotted, and has not been added to thePlotCanvas.dataSerieslist, is added to said list.Removes the most recently added
DataSeriesfrom thePlotCanvas.dataSeries.Proxy images
The
OverlayPlotPanelwill replace allProxyImageinstances with their base images. This functionality was originally added to support theHistogramSeries.showOverlayfunctionality - it adds a mask image to theOverlayListto display the histogram range. Sub-classes may wish to adhere to the same logic (replacingProxyImageinstances with their bases)Control panels
The
PlotControlPanel,PlotListPanel, andOverlayListPanelare FSLeyes control panels which work with theOverlayPlotPanel. ThePlotControlPanelis 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
OverlayPlotPanelis the base class for:The
TimeSeriesPanelis anOverlayPlotPanelwhich plots time series data from overlays.An
OverlayPlotPanelwhich plots histograms fromImageoverlay data.The
PowerSpectrumPanelclass is anOverlayPlotPanelwhich plots power spectra of overlay data.-
plotColours= {}¶ This dictionary is used to store a collection of
{overlay : colour}mappings. It is shared across allOverlayPlotPanelinstances, 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
OverlayPlotPanelis no longer needed. Removes some property listeners, and callsPlotPanel.destroy().
-
getDataSeriesToPlot()[source]¶ Convenience method which returns a list of overlays which have
DataSeriesthat should be plotted.
-
getDataSeries(overlay)[source]¶ Returns the
DataSeriesinstance associated with the specified overlay, orNoneif there is noDataSeriesinstance.
-
getOverlayPlotColour(overlay)[source]¶ Returns an initial colour to use for plots associated with the given overlay. If a colour is present in the
plotColoursdictionary, 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
plotStylesdictionary, 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
linestyleargument of thematplotlibplotfunctions.
-
addDataSeries()[source]¶ Every
DataSerieswhich is currently plotted, and has not been added to thePlotCanvas.dataSerieslist, is added to said list.
-
removeDataSeries(*a)[source]¶ Removes the most recently added
DataSeriesfrom thePlotCanvas.dataSeries.
-
createDataSeries(overlay)[source]¶ This method must be implemented by sub-classes. It must create and return a
DataSeriesinstance for the specified overlay.Note
Sub-class implementations should set the
DataSeries.colourproperty to that returned by thegetOverlayPlotColour()method, and theDataSeries.lineStyleproperty to that returned by thegetOverlayPlotStyle()methodDifferent
DataSeriestypes need to be re-drawn when different properties change. For example, aVoxelTimeSeries`instance needs to be redrawn when theDisplayContext.locationproperty changes, whereas aMelodicTimeSeriesinstance needs to be redrawn when theVolumeOpts.volumeproperty changes.Therefore, in addition to creating and returning a
DataSeriesinstance for the given overlay, sub-class implementations must also specify the properties which affect the state of theDataSeriesinstance. These must be specified as two lists:the targets list, a list of objects which own the dependant properties (e.g. the
DisplayContextorVolumeOptsinstance).The properties list, a list of names, each specifying the property on the corresponding target.
This method must therefore return a tuple containing:
A
DataSeriesinstance, orNoneif 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
DataSeriesfor the given overlay.
-
updateDataSeries(initialState=None)[source]¶ Makes sure that a
DataSeriesinstance 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
dictof{ overlay : bool }mappings, specifying the initial value of theDataSeries.enabledproperty 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.dataSerieslist changes. Enables/disables theremoveDataSeries()action accordingly.
-
__module__= 'fsleyes.views.plotpanel'¶
-
__overlayListChanged(*a, **kwa)¶ Called when the
OverlayListchanges. Makes sure that there are noDataSeriesinstances in thePlotCanvas.dataSerieslist, 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.