我正在PyQwt中创建一个Nyquist图。当前有效,除了我需要翻转y轴-约定的底部为零,上移时为负数。
我知道您将在C ++中执行此操作,但无法弄清楚如何在Python中执行此操作。我不完全了解Qt / Qwt如何转换为PyQt / PyQwt。根据http://qwt.sourceforge.net/class_qwt_scale_engine.html,有一个属性Inverted
需要设置。在C ++中,这看起来像:
ui.plotWidget->axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Inverted, true);
我想不出一种方法,在主窗口中尝试了几种方法__init__(self)
:
self.ui.qwtPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Imaginary Impedance')
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtScaleEngine.Inverted))
# TypeError: QwtPlot.setAxisScaleEngine(): argument 2 has unexpected type 'Attribute'
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtScaleEngine.setAttribute(Inverted))
# NameError: global name 'Inverted' is not defined
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtScaleEngine.setAttribute(Qwt.QwtScaleEngine.Inverted)
# TypeError: QwtScaleEngine.setAttribute(): first argument of unbound method must have type 'QwtScaleEngine'
我还尝试定义一个新类,就像在http://sourceforge.net/p/pyqwt/patches/1/中所做的那样:
class InvertedAxisEngine(Qwt.QwtScaleEngine):
def __init__(self):
Qwt.QwtScaleEngine.__init__(self)
self.setAttribute(Qwt.QwtScaleEngine.Inverted)
# back in Window.__init__(self)
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, InvertedAxisEngine)
#TypeError: QwtPlot.setAxisScaleEngine(): argument 2 has unexpected type 'PyQt4.QtCore.pyqtWrapperType'
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, InvertedAxisEngine())
# NotImplementedError: QwtScaleEngine.divideScale() is abstract and must be overridden
#NotImplementedError: QwtScaleEngine.transformation() is abstract and must be overridden
我感觉到我把它弄得太复杂了。
编辑-下面的注释启发了几件事,例如添加=True
到Inverted
(不,没有关键字参数,我也尝试过这样做,这对unexpected type
(包装器)有所帮助。
self.ui.inverted_engine = Qwt.QwtScaleEngine
self.ui.inverted_engine.Inverted = True
self.ui.qwtPlot.setAxisScaleEngine(Qwt.QwtPlot.yLeft, self.ui.inverted_engine)
当GUI运行时,我没有解释器提示访问权限,但是我print dir(Qwt.QwtScaleEngine)
在init中添加了a ,它确实存在:['Attribute', 'Floating', 'IncludeReference', 'Inverted', 'NoAttribute', 'Symmetric', '__class__',....
在检查http://orange.biolab.si/svn/orange/externals/trunk/install-scripts/mac/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/上的代码后,我终于找到了答案2.6 / lib目录/ python2.6的/站点包/ PyQt4的/ Qwt5 / qplt.py。我认为还可以使用来实现此目的setAxisScaleEngine()
,但这是可行的。
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.qwtPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Imaginary Impedance (ohms)')
self.ui.qwtPlot.setCanvasBackground(Qt.white)
engine = self.ui.qwtPlot.axisScaleEngine(Qwt.QwtPlot.yLeft)
Qwt.QwtScaleEngine.setAttribute(engine, Qwt.QwtScaleEngine.Inverted)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句