aboutsummaryrefslogtreecommitdiffstats
path: root/examples/external/matplotlib
diff options
context:
space:
mode:
Diffstat (limited to 'examples/external/matplotlib')
-rw-r--r--examples/external/matplotlib/widget3d/doc/widget3d.pngbin0 -> 135383 bytes
-rw-r--r--examples/external/matplotlib/widget3d/doc/widget3d.rst9
-rw-r--r--examples/external/matplotlib/widget3d/requirements.txt (renamed from examples/external/matplotlib/requirements.txt)1
-rw-r--r--examples/external/matplotlib/widget3d/widget3d.py (renamed from examples/external/matplotlib/widget_3dplot.py)75
-rw-r--r--examples/external/matplotlib/widget3d/widget3d.pyproject3
-rw-r--r--examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.pngbin0 -> 16198 bytes
-rw-r--r--examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.rst9
-rw-r--r--examples/external/matplotlib/widget_gaussian/requirements.txt3
-rw-r--r--examples/external/matplotlib/widget_gaussian/widget_gaussian.py74
-rw-r--r--examples/external/matplotlib/widget_gaussian/widget_gaussian.pyproject3
10 files changed, 122 insertions, 55 deletions
diff --git a/examples/external/matplotlib/widget3d/doc/widget3d.png b/examples/external/matplotlib/widget3d/doc/widget3d.png
new file mode 100644
index 000000000..fa2ed5043
--- /dev/null
+++ b/examples/external/matplotlib/widget3d/doc/widget3d.png
Binary files differ
diff --git a/examples/external/matplotlib/widget3d/doc/widget3d.rst b/examples/external/matplotlib/widget3d/doc/widget3d.rst
new file mode 100644
index 000000000..b5c9fd8fd
--- /dev/null
+++ b/examples/external/matplotlib/widget3d/doc/widget3d.rst
@@ -0,0 +1,9 @@
+Matplotlib Widget 3D Example
+============================
+
+A Python application that demonstrates how to combine matplotlib
+with Qt Widget-based functionality.
+
+.. image:: widget3d.png
+ :width: 400
+ :alt: Matplotlib Widget 3D Screenshot
diff --git a/examples/external/matplotlib/requirements.txt b/examples/external/matplotlib/widget3d/requirements.txt
index 6ccafc3f9..db5d81e01 100644
--- a/examples/external/matplotlib/requirements.txt
+++ b/examples/external/matplotlib/widget3d/requirements.txt
@@ -1 +1,2 @@
matplotlib
+numpy
diff --git a/examples/external/matplotlib/widget_3dplot.py b/examples/external/matplotlib/widget3d/widget3d.py
index b96405661..8bfcc4ca2 100644
--- a/examples/external/matplotlib/widget_3dplot.py
+++ b/examples/external/matplotlib/widget3d/widget3d.py
@@ -1,52 +1,15 @@
-#############################################################################
-##
-## Copyright (C) 2020 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## You may use this file under the terms of the BSD license as follows:
-##
-## "Redistribution and use in source and binary forms, with or without
-## modification, are permitted provided that the following conditions are
-## met:
-## * Redistributions of source code must retain the above copyright
-## notice, this list of conditions and the following disclaimer.
-## * Redistributions in binary form must reproduce the above copyright
-## notice, this list of conditions and the following disclaimer in
-## the documentation and/or other materials provided with the
-## distribution.
-## * Neither the name of The Qt Company Ltd nor the names of its
-## contributors may be used to endorse or promote products derived
-## from this software without specific prior written permission.
-##
-##
-## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import sys
import numpy as np
-from matplotlib.backends.backend_qt5agg import FigureCanvas
+from matplotlib.backends.backend_qtagg import FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import axes3d
-from PySide2.QtCore import Qt, Slot
-from PySide2.QtGui import QKeySequence
-from PySide2.QtWidgets import (QAction, QApplication, QComboBox, QHBoxLayout,
+from PySide6.QtCore import Qt, Slot
+from PySide6.QtGui import QAction, QKeySequence
+from PySide6.QtWidgets import (QApplication, QComboBox, QHBoxLayout,
QHeaderView, QLabel, QMainWindow, QSlider,
QTableWidget, QTableWidgetItem, QVBoxLayout,
QWidget)
@@ -69,12 +32,12 @@ class ApplicationWindow(QMainWindow):
# Main menu bar
self.menu = self.menuBar()
self.menu_file = self.menu.addMenu("File")
- exit = QAction("Exit", self, triggered=qApp.quit)
+ exit = QAction("Exit", self, triggered=qApp.quit) # noqa: F821
self.menu_file.addAction(exit)
self.menu_about = self.menu.addMenu("&About")
about = QAction("About Qt", self, shortcut=QKeySequence(QKeySequence.HelpContents),
- triggered=qApp.aboutQt)
+ triggered=qApp.aboutQt) # noqa: F821
self.menu_about.addAction(about)
# Figure (Left)
@@ -82,18 +45,20 @@ class ApplicationWindow(QMainWindow):
self.canvas = FigureCanvas(self.fig)
# Sliders (Left)
- self.slider_azim = QSlider(minimum=0, maximum=360, orientation=Qt.Horizontal)
- self.slider_elev = QSlider(minimum=0, maximum=360, orientation=Qt.Horizontal)
+ min = 0
+ max = 360
+ self.slider_azim = QSlider(minimum=min, maximum=max, orientation=Qt.Horizontal)
+ self.slider_elev = QSlider(minimum=min, maximum=max, orientation=Qt.Horizontal)
self.slider_azim_layout = QHBoxLayout()
- self.slider_azim_layout.addWidget(QLabel("{}".format(self.slider_azim.minimum())))
+ self.slider_azim_layout.addWidget(QLabel(f"{min}"))
self.slider_azim_layout.addWidget(self.slider_azim)
- self.slider_azim_layout.addWidget(QLabel("{}".format(self.slider_azim.maximum())))
+ self.slider_azim_layout.addWidget(QLabel(f"{max}"))
self.slider_elev_layout = QHBoxLayout()
- self.slider_elev_layout.addWidget(QLabel("{}".format(self.slider_elev.minimum())))
+ self.slider_elev_layout.addWidget(QLabel(f"{min}"))
self.slider_elev_layout.addWidget(self.slider_elev)
- self.slider_elev_layout.addWidget(QLabel("{}".format(self.slider_elev.maximum())))
+ self.slider_elev_layout.addWidget(QLabel(f"{max}"))
# Table (Right)
self.table = QTableWidget()
@@ -147,9 +112,9 @@ class ApplicationWindow(QMainWindow):
def set_table_data(self, X, Y, Z):
for i in range(len(X)):
- self.table.setItem(i, 0, QTableWidgetItem("{:.2f}".format(X[i])))
- self.table.setItem(i, 1, QTableWidgetItem("{:.2f}".format(Y[i])))
- self.table.setItem(i, 2, QTableWidgetItem("{:.2f}".format(Z[i])))
+ self.table.setItem(i, 0, QTableWidgetItem(f"{X[i]:.2f}"))
+ self.table.setItem(i, 1, QTableWidgetItem(f"{Y[i]:.2f}"))
+ self.table.setItem(i, 2, QTableWidgetItem(f"{Z[i]:.2f}"))
def set_canvas_table_configuration(self, row_count, data):
self.fig.set_canvas(self.canvas)
@@ -239,4 +204,4 @@ if __name__ == "__main__":
w = ApplicationWindow()
w.setFixedSize(1280, 720)
w.show()
- app.exec_()
+ app.exec()
diff --git a/examples/external/matplotlib/widget3d/widget3d.pyproject b/examples/external/matplotlib/widget3d/widget3d.pyproject
new file mode 100644
index 000000000..6b25c5be7
--- /dev/null
+++ b/examples/external/matplotlib/widget3d/widget3d.pyproject
@@ -0,0 +1,3 @@
+{
+ "files": ["widget3d.py"]
+}
diff --git a/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.png b/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.png
new file mode 100644
index 000000000..e9fe16354
--- /dev/null
+++ b/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.png
Binary files differ
diff --git a/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.rst b/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.rst
new file mode 100644
index 000000000..467fb42c2
--- /dev/null
+++ b/examples/external/matplotlib/widget_gaussian/doc/widget_gaussian.rst
@@ -0,0 +1,9 @@
+Matplotlib Widget Gaussian Example
+==================================
+
+A Python application that demonstrates how to interact with
+matplotlib and scipy, combined with Qt Widgets.
+
+.. image:: widget_gaussian.png
+ :width: 400
+ :alt: Matplotlib Widget Gaussian Screenshot
diff --git a/examples/external/matplotlib/widget_gaussian/requirements.txt b/examples/external/matplotlib/widget_gaussian/requirements.txt
new file mode 100644
index 000000000..26a2b438f
--- /dev/null
+++ b/examples/external/matplotlib/widget_gaussian/requirements.txt
@@ -0,0 +1,3 @@
+matplotlib
+scipy
+numpy
diff --git a/examples/external/matplotlib/widget_gaussian/widget_gaussian.py b/examples/external/matplotlib/widget_gaussian/widget_gaussian.py
new file mode 100644
index 000000000..2423e496a
--- /dev/null
+++ b/examples/external/matplotlib/widget_gaussian/widget_gaussian.py
@@ -0,0 +1,74 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import sys
+
+import numpy as np
+from scipy.stats import norm
+from matplotlib.figure import Figure
+from matplotlib.backends.backend_qtagg import FigureCanvas
+from matplotlib.backends.backend_qtagg import NavigationToolbar2QT
+from PySide6.QtCore import Slot
+from PySide6.QtWidgets import (
+ QApplication,
+ QWidget,
+ QDoubleSpinBox,
+ QVBoxLayout,
+ QHBoxLayout,
+)
+
+
+"""This example implements the interaction between Qt Widgets and a 2D
+matplotlib plot showing a gaussian curve with scipy"""
+
+
+class PlotWidget(QWidget):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+
+ #  create widgets
+ self.view = FigureCanvas(Figure(figsize=(5, 3)))
+ self.axes = self.view.figure.subplots()
+ self.toolbar = NavigationToolbar2QT(self.view, self)
+ self.mu_input = QDoubleSpinBox()
+ self.std_input = QDoubleSpinBox()
+ self.mu_input.setPrefix("μ: ")
+ self.std_input.setPrefix("σ: ")
+ self.std_input.setValue(10)
+
+ #  Create layout
+ input_layout = QHBoxLayout()
+ input_layout.addWidget(self.mu_input)
+ input_layout.addWidget(self.std_input)
+ vlayout = QVBoxLayout()
+ vlayout.addWidget(self.toolbar)
+ vlayout.addWidget(self.view)
+ vlayout.addLayout(input_layout)
+ self.setLayout(vlayout)
+
+ # connect inputs with on_change method
+ self.mu_input.valueChanged.connect(self.on_change)
+ self.std_input.valueChanged.connect(self.on_change)
+
+ self.on_change()
+
+ @Slot()
+ def on_change(self):
+ """ Update the plot with the current input values """
+ mu = self.mu_input.value()
+ std = self.std_input.value()
+
+ x = np.linspace(-100, 100)
+ y = norm.pdf(x, mu, std)
+
+ self.axes.clear()
+ self.axes.plot(x, y)
+ self.view.draw()
+
+
+if __name__ == "__main__":
+
+ app = QApplication(sys.argv)
+ w = PlotWidget()
+ w.show()
+ sys.exit(app.exec())
diff --git a/examples/external/matplotlib/widget_gaussian/widget_gaussian.pyproject b/examples/external/matplotlib/widget_gaussian/widget_gaussian.pyproject
new file mode 100644
index 000000000..72c5adc78
--- /dev/null
+++ b/examples/external/matplotlib/widget_gaussian/widget_gaussian.pyproject
@@ -0,0 +1,3 @@
+{
+ "files": ["widget_gaussian.py"]
+}