概述
下面是Qt Designer的MatplotlibPlugin的PyQt5版本。在
要使用它,请将这两个文件放在PYQTDESIGNERPATH环境变量中包含的目录中,或者放在directories that Qt Designer searches for its own plugins中某个“python”子目录中。这两个文件的名称必须完全如下所示。在
matplotlibwidget.py:from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QSizePolicy
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
from matplotlib.figure import Figure
from matplotlib import rcParams
rcParams['font.size'] = 9
class MatplotlibWidget(Canvas):
def __init__(self, parent=None, title='', xlabel='', ylabel='',
xlim=None, ylim=None, xscale='linear', yscale='linear',
width=4, height=3, dpi=100):
self.figure = Figure(figsize=(width, height), dpi=dpi)
self.axes = self.figure.add_subplot(111)
self.axes.set_title(title)
self.axes.set_xlabel(xlabel)
self.axes.set_ylabel(ylabel)
if xscale is not None:
self.axes.set_xscale(xscale)
if yscale is not None:
self.axes.set_yscale(yscale)
if xlim is not None:
self.axes.set_xlim(*xlim)
if ylim is not None:
self.axes.set_ylim(*ylim)
super(MatplotlibWidget, self).__init__(self.figure)
self.setParent(parent)
super(MatplotlibWidget, self).setSizePolicy(
QSizePolicy.Expanding, QSizePolicy.Expanding)
super(MatplotlibWidget, self).updateGeometry()
def sizeHint(self):
return QSize(*self.get_width_height())
def minimumSizeHint(self):
return QSize(10, 10)
matplotlibplugin.py:
^{pr2}$
最后
以上就是贪玩机器猫为你收集整理的qt插件开发python_Qt5 Matplotlib设计器插件的全部内容,希望文章能够帮你解决qt插件开发python_Qt5 Matplotlib设计器插件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复