"""
This widget contains the layout for graphs which use the matplotlib
library to generate graphs. The widget can be executed as a standalone
version.
Note:
Generally, for all experiments pyqt graph was used for performance
issues. However, this widget also works and should not be deleted
because it might become usefull in the future if the tasks are not
computationally expensive. Additionally, some experiments (e.g.
show_signal) have a working matplotlib class which is currently not
used.
########################################
Functionalities provided in this widget:
########################################
1. Provides a canvas to plot graphs into it.
2. Provides a toolbar with an autoscale check box.
3. Provides clearing of canvas if plots are consecutively drawn (i.e. in
a for loop).
"""
if __name__ == "__main__":
# Add directories to path for imports
import os, sys, inspect
currentdir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
)
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, os.path.join(currentdir, "ui_files"))
sys.path.insert(0, parentdir)
# PyQt imports
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QRunnable, QThreadPool
from PyQt5 import QtCore, QtGui, QtWidgets
import matplotlib
matplotlib.use("Qt5Agg")
from matplotlib.backends.backend_qt5agg import (
FigureCanvasQTAgg,
NavigationToolbar2QT as NavigationToolbar,
)
from matplotlib.figure import Figure
import numpy as np
from matplotlib.figure import Figure
[docs]class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
# self.axes = fig.add_subplot(111)
super(MplCanvas, self).__init__(fig)
if __name__ == "__main__":
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Please god let this work too")
widget = MplWidget(self)
self.setCentralWidget(widget)
self.show()
ax = widget.canvas.figure.add_subplot(211)
ax.plot(np.arange(10))
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
app.exec_()