我要在一个具有2个y轴的视图框中绘制两个波德图,一个在左侧,另一个在右侧。 问题是我无法将一个轴设置为对数模式,而另一个轴设置为正常模式。 两者都处于日志模式或正常模式(使用setLogMode(True,False))。
# -*- coding: utf-8 -*-
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import control
pg.mkQApp()
pw = pg.PlotWidget()
pw.show()
p1 = pw.plotItem
p1.setLabels(left='axis 1')
p2 = pg.ViewBox()
p1.showAxis('right')
p1.scene().addItem(p2)
p1.getAxis('right').linkToView(p2)
p2.setXLink(p1)
p1.getAxis('right').setLabel('axis2', color='#0000ff')
## Handle view resizing
def updateViews():
## view has resized; update auxiliary views to match
global p1, p2
p2.setGeometry(p1.vb.sceneBoundingRect())
p2.linkedViewChanged(p1.vb, p2.XAxis)
updateViews()
p1.vb.sigResized.connect(updateViews)
G = 0.2*control.tf([0.5,1],[1.5,0.5,1])
(num,den) = control.pade(0.25,3)
Gp = control.tf(num,den)*G
f = np.logspace(-2, 4,1000)
mag, phase, omega = control.bode(Gp, f)
phase_degree = (phase * 180 / np.pi)
pw.setBackground('#FFFFFF')
# plot
p1.setLogMode(True, False)
p1.addItem(pw.plot(f,phase_degree , movable=True))
p2.addItem(pw.plot(f, mag, movable=True))
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()