英文:
Integrating matplotlib in pyqt interface using matplotlib_backend_qtquick
问题
我需要在我的pyqt界面窗口中显示一些matplotlib.pyplot的3D图形。试图使用类似于这个的实现,借助库matplotlib_backend_qtquick的帮助。
以下是我的main.py
代码部分:
import os
import sys
from PyQt5 import QtQml, QtCore
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from matplotlib_backend_qtquick.backend_qtquickagg import FigureCanvasQtQuickAgg
os.environ['QT_QUICK_CONTROLS_STYLE'] = "Material"
QtQml.qmlRegisterType(FigureCanvasQtQuickAgg, "Backend", 1, 0, "FigureCanvas")
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl.fromLocalFile('/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/pyqt5_qtquick2_example/qml/main.qml'))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
当我尝试运行我的main.py
时,我收到了以下错误回溯信息:
Traceback (most recent call last):
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/main.py", line 10, in <module>
from matplotlib_backend_qtquick.backend_qtquickagg import FigureCanvasQtQuickAgg
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib_backend_qtquick/backend_qtquickagg.py", line 7, in <module>
from .backend_qtquick import (
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib_backend_qtquick/backend_qtquick.py", line 11, in <module>
from matplotlib.backends.backend_qt5 import (
ImportError: cannot import name 'MODIFIER_KEYS' from 'matplotlib.backends.backend_qt5' (/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib/backends/backend_qt5.py)
Process finished with exit code 1
我做错了什么?
英文:
I need to show some matplotlib.pyplot 3d graphics in my pyqt interface window. Trying to implement something like this with the help of library matplotlib_backend_qtquick.
Here is my main.py
:
import os
import sys
from PyQt5 import QtQml, QtCore
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from matplotlib_backend_qtquick.backend_qtquickagg import FigureCanvasQtQuickAgg
os.environ['QT_QUICK_CONTROLS_STYLE'] = "Material"
QtQml.qmlRegisterType(FigureCanvasQtQuickAgg, "Backend", 1, 0, "FigureCanvas")
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl.fromLocalFile('/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/pyqt5_qtquick2_example/qml/main.qml'))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
When I'm trying to run my main.py
I got a traceback:
Traceback (most recent call last):
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/main.py", line 10, in <module>
from matplotlib_backend_qtquick.backend_qtquickagg import FigureCanvasQtQuickAgg
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib_backend_qtquick/backend_qtquickagg.py", line 7, in <module>
from .backend_qtquick import (
File "/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib_backend_qtquick/backend_qtquick.py", line 11, in <module>
from matplotlib.backends.backend_qt5 import (
ImportError: cannot import name 'MODIFIER_KEYS' from 'matplotlib.backends.backend_qt5' (/home/vovi/PycharmProjects/pyqt5-qtquick2-example-master/pyqt5-qtquick2-example-master/venv/lib/python3.11/site-packages/matplotlib/backends/backend_qt5.py)
Process finished with exit code 1
What am I doing wrong?
答案1
得分: 1
matplotlib_backend_qtquick
库不再维护。它现在已经损坏,因为至少它使用了旧版Matplotlib的内部符号 - MODIFIER_KEYS
。README
中写着它适用于Matplotlib 3.2.1版本。
所以要么使用Matplotlib 3.2.1版本,要么自己移植这个库。
英文:
That matplotlib_backend_qtquick
library is not maintained anymore. It's broken now because at least it was using an internal symbol of an old Matplotlib version - MODIFIER_KEYS
. The README
says it worked with Matplotlib 3.2.1.
So either use Matplotlib 3.2.1 version or port the library yourself.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论