Source code for titania.plots.base_plot

from abc import ABC, abstractmethod
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from PyQt5.QtWidgets import QWidget
from titania.common.interface_tab import TitaniaTabInterface


[docs]class PlotInterface(ABC): """ Basic plotting interface for titania """
[docs] @abstractmethod def get_as_plot_widget(self) -> QWidget : """ If the plot is a more complex QWidget, it should return that widget """ pass
[docs] def pre_draw(self): """ Actions to be done before drawing the plot """ pass
[docs] @abstractmethod def draw_plot(self) : """ Draws the plot """ pass
[docs]class FinalMetaPlot(type(PlotInterface), type(FigureCanvas)): pass
[docs]class BaseCanvasPlot(PlotInterface, FigureCanvas, metaclass=FinalMetaPlot): def __init__(self, parent : QWidget = None, view : TitaniaTabInterface =None): """ Implements qt canvas with matplotlib """ plt.rcParams.update({'figure.max_open_warning': 0}) self.parent = parent self.plot_number = 111 self.figure = plt.figure() self.view = view FigureCanvas.__init__(self, self.figure)
[docs] def get_as_plot_widget(self): return self
[docs]class MplPlot(BaseCanvasPlot): """ A parent class for making matplotlib plots """
[docs] def get_as_plot_widget(self, row=0): return self
[docs] def pre_draw(self): self.figure.clear()