本文整理汇总了Python中matplotlib.backends.backend_qt5agg.NavigationToolbar2QT.actions方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QT.actions方法的具体用法?Python NavigationToolbar2QT.actions怎么用?Python NavigationToolbar2QT.actions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt5agg.NavigationToolbar2QT
的用法示例。
在下文中一共展示了NavigationToolbar2QT.actions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VNA
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import actions [as 别名]
class VNA(QMainWindow, Ui_VNA):
max_size = 16384
def __init__(self):
super(VNA, self).__init__()
self.setupUi(self)
# IP address validator
rx = QRegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
self.addrValue.setValidator(QRegExpValidator(rx, self.addrValue))
# state variables
self.idle = True
self.reading = False
# sweep parameters
self.sweep_start = 100
self.sweep_stop = 60000
self.sweep_size = 600
self.xaxis, self.sweep_step = np.linspace(self.sweep_start, self.sweep_stop, self.sweep_size, retstep = True)
self.xaxis *= 1000
# buffer and offset for the incoming samples
self.buffer = bytearray(24 * VNA.max_size)
self.offset = 0
self.data = np.frombuffer(self.buffer, np.complex64)
self.adc1 = np.zeros(VNA.max_size, np.complex64)
self.adc2 = np.zeros(VNA.max_size, np.complex64)
self.dac1 = np.zeros(VNA.max_size, np.complex64)
self.open = np.zeros(VNA.max_size, np.complex64)
self.short = np.zeros(VNA.max_size, np.complex64)
self.load = np.zeros(VNA.max_size, np.complex64)
self.dut = np.zeros(VNA.max_size, np.complex64)
self.mode = 'dut'
# create figure
self.figure = Figure()
self.figure.set_facecolor('none')
self.canvas = FigureCanvas(self.figure)
self.plotLayout.addWidget(self.canvas)
# create navigation toolbar
self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False)
# initialize cursor
self.cursor = None
# remove subplots action
actions = self.toolbar.actions()
self.toolbar.removeAction(actions[7])
self.plotLayout.addWidget(self.toolbar)
# create TCP socket
self.socket = QTcpSocket(self)
self.socket.connected.connect(self.connected)
self.socket.readyRead.connect(self.read_data)
self.socket.error.connect(self.display_error)
# connect signals from buttons and boxes
self.sweepFrame.setEnabled(False)
self.dutSweep.setEnabled(False)
self.connectButton.clicked.connect(self.start)
self.writeButton.clicked.connect(self.write_cfg)
self.readButton.clicked.connect(self.read_cfg)
self.openSweep.clicked.connect(self.sweep_open)
self.shortSweep.clicked.connect(self.sweep_short)
self.loadSweep.clicked.connect(self.sweep_load)
self.dutSweep.clicked.connect(self.sweep_dut)
self.csvButton.clicked.connect(self.write_csv)
self.s1pButton.clicked.connect(self.write_s1p)
self.s2pButton.clicked.connect(self.write_s2p)
self.startValue.valueChanged.connect(self.set_start)
self.stopValue.valueChanged.connect(self.set_stop)
self.sizeValue.valueChanged.connect(self.set_size)
self.rateValue.addItems(['500', '100', '50', '10', '5', '1'])
self.rateValue.lineEdit().setReadOnly(True)
self.rateValue.lineEdit().setAlignment(Qt.AlignRight)
for i in range(0, self.rateValue.count()):
self.rateValue.setItemData(i, Qt.AlignRight, Qt.TextAlignmentRole)
self.rateValue.currentIndexChanged.connect(self.set_rate)
self.corrValue.valueChanged.connect(self.set_corr)
self.levelValue.valueChanged.connect(self.set_level)
self.openPlot.clicked.connect(self.plot_open)
self.shortPlot.clicked.connect(self.plot_short)
self.loadPlot.clicked.connect(self.plot_load)
self.dutPlot.clicked.connect(self.plot_dut)
self.smithPlot.clicked.connect(self.plot_smith)
self.impPlot.clicked.connect(self.plot_imp)
self.rcPlot.clicked.connect(self.plot_rc)
self.swrPlot.clicked.connect(self.plot_swr)
self.rlPlot.clicked.connect(self.plot_rl)
self.gainPlot.clicked.connect(self.plot_gain)
# create timer
self.startTimer = QTimer(self)
self.startTimer.timeout.connect(self.timeout)
def start(self):
if self.idle:
self.connectButton.setEnabled(False)
self.socket.connectToHost(self.addrValue.text(), 1001)
self.startTimer.start(5000)
else:
self.stop()
def stop(self):
self.idle = True
self.socket.abort()
self.connectButton.setText('Connect')
self.connectButton.setEnabled(True)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import actions [as 别名]
class FigureTab:
cursors = [15000, 45000]
colors = ['orange', 'violet']
def __init__(self, layout, vna):
# create figure
self.figure = Figure()
if sys.platform != 'win32':
self.figure.set_facecolor('none')
self.canvas = FigureCanvas(self.figure)
layout.addWidget(self.canvas)
# create navigation toolbar
self.toolbar = NavigationToolbar(self.canvas, None, False)
self.toolbar.layout().setSpacing(6)
# remove subplots action
actions = self.toolbar.actions()
if int(matplotlib.__version__[0]) < 2:
self.toolbar.removeAction(actions[7])
else:
self.toolbar.removeAction(actions[6])
self.toolbar.addSeparator()
self.cursorLabels = {}
self.cursorValues = {}
self.cursorMarkers = {}
self.cursorPressed = {}
for i in range(len(self.cursors)):
self.cursorMarkers[i] = None
self.cursorPressed[i] = False
self.cursorLabels[i] = QLabel('Cursor %d, kHz' % (i + 1))
self.cursorLabels[i].setStyleSheet('color: %s' % self.colors[i])
self.cursorValues[i] = QSpinBox()
self.cursorValues[i].setMinimumSize(90, 0)
self.cursorValues[i].setSingleStep(10)
self.cursorValues[i].setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
self.toolbar.addWidget(self.cursorLabels[i])
self.toolbar.addWidget(self.cursorValues[i])
self.cursorValues[i].valueChanged.connect(partial(self.set_cursor, i))
self.canvas.mpl_connect('button_press_event', partial(self.press_marker, i))
self.canvas.mpl_connect('motion_notify_event', partial(self.move_marker, i))
self.canvas.mpl_connect('button_release_event', partial(self.release_marker, i))
self.toolbar.addSeparator()
self.plotButton = QPushButton('Rescale')
self.toolbar.addWidget(self.plotButton)
layout.addWidget(self.toolbar)
self.plotButton.clicked.connect(self.plot)
self.mode = None
self.vna = vna
def add_cursors(self, axes):
if self.mode == 'gain_short' or self.mode == 'gain_open':
columns = ['Freq., kHz', 'G, dB', r'$\angle$ G, deg']
else:
columns = ['Freq., kHz', 'Re(Z), \u03A9', 'Im(Z), \u03A9', '|Z|, \u03A9', r'$\angle$ Z, deg', 'SWR', r'|$\Gamma$|', r'$\angle$ $\Gamma$, deg', 'RL, dB']
y = len(self.cursors) * 0.04 + 0.01
for i in range(len(columns)):
self.figure.text(0.19 + 0.1 * i, y, columns[i], horizontalalignment = 'right')
self.cursorRows = {}
for i in range(len(self.cursors)):
y = len(self.cursors) * 0.04 - 0.03 - 0.04 * i
self.figure.text(0.01, y, 'Cursor %d' % (i + 1), color = self.colors[i])
self.cursorRows[i] = {}
for j in range(len(columns)):
self.cursorRows[i][j] = self.figure.text(0.19 + 0.1 * j, y, '', horizontalalignment = 'right')
if self.mode == 'smith':
self.cursorMarkers[i], = axes.plot(0.0, 0.0, marker = 'o', color = self.colors[i])
else:
self.cursorMarkers[i] = axes.axvline(0.0, color = self.colors[i], linewidth = 2)
self.set_cursor(i, self.cursorValues[i].value())
def set_cursor(self, index, value):
FigureTab.cursors[index] = value
marker = self.cursorMarkers[index]
if marker is None: return
row = self.cursorRows[index]
freq = value
gamma = self.vna.gamma(freq)
if self.mode == 'smith':
marker.set_xdata(gamma.real)
marker.set_ydata(gamma.imag)
else:
marker.set_xdata(freq)
row[0].set_text('%d' % freq)
if self.mode == 'gain_short':
gain = self.vna.gain_short(freq)
magnitude = 20.0 * np.log10(np.absolute(gain))
angle = np.angle(gain, deg = True)
row[1].set_text(unicode_minus('%.1f' % magnitude))
row[2].set_text(unicode_minus('%.1f' % angle))
elif self.mode == 'gain_open':
gain = self.vna.gain_open(freq)
magnitude = 20.0 * np.log10(np.absolute(gain))
angle = np.angle(gain, deg = True)
row[1].set_text(unicode_minus('%.1f' % magnitude))
row[2].set_text(unicode_minus('%.1f' % angle))
else:
swr = self.vna.swr(freq)
z = self.vna.impedance(freq)
rl = 20.0 * np.log10(np.absolute(gamma))
if rl > -0.01: rl = 0.0
row[1].set_text(metric_prefix(z.real))
#.........这里部分代码省略.........
示例3: VNA
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import actions [as 别名]
class VNA(QMainWindow, Ui_VNA):
max_size = 16383
formatter = matplotlib.ticker.FuncFormatter(lambda x, pos: '%1.1fM' % (x * 1e-6) if abs(x) >= 1e6 else '%1.1fk' % (x * 1e-3) if abs(x) >= 1e3 else '%1.1f' % x if abs(x) >= 1e0 else '%1.1fm' % (x * 1e+3) if abs(x) >= 1e-3 else '%1.1fu' % (x * 1e+6) if abs(x) >= 1e-6 else '%1.1f' % x)
def __init__(self):
super(VNA, self).__init__()
self.setupUi(self)
# IP address validator
rx = QRegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
self.addrValue.setValidator(QRegExpValidator(rx, self.addrValue))
# state variable
self.idle = True
# sweep parameters
self.sweep_start = 100
self.sweep_stop = 60000
self.sweep_size = 600
self.xaxis, self.sweep_step = np.linspace(self.sweep_start, self.sweep_stop, self.sweep_size, retstep = True)
self.xaxis *= 1000
# buffer and offset for the incoming samples
self.buffer = bytearray(32 * VNA.max_size)
self.offset = 0
self.data = np.frombuffer(self.buffer, np.complex64)
self.adc1 = np.zeros(VNA.max_size, np.complex64)
self.adc2 = np.zeros(VNA.max_size, np.complex64)
self.dac1 = np.zeros(VNA.max_size, np.complex64)
self.open = np.zeros(VNA.max_size, np.complex64)
self.short = np.zeros(VNA.max_size, np.complex64)
self.load = np.zeros(VNA.max_size, np.complex64)
self.dut = np.zeros(VNA.max_size, np.complex64)
self.mode = 'dut'
# create figure
self.figure = Figure()
self.figure.set_facecolor('none')
self.canvas = FigureCanvas(self.figure)
self.plotLayout.addWidget(self.canvas)
# create navigation toolbar
self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False)
# remove subplots action
actions = self.toolbar.actions()
self.toolbar.removeAction(actions[7])
self.plotLayout.addWidget(self.toolbar)
# create TCP socket
self.socket = QTcpSocket(self)
self.socket.connected.connect(self.connected)
self.socket.readyRead.connect(self.read_data)
self.socket.error.connect(self.display_error)
# connect signals from buttons and boxes
self.sweepFrame.setEnabled(False)
self.dutSweep.setEnabled(False)
self.connectButton.clicked.connect(self.start)
self.writeButton.clicked.connect(self.write_cfg)
self.readButton.clicked.connect(self.read_cfg)
self.openSweep.clicked.connect(self.sweep_open)
self.shortSweep.clicked.connect(self.sweep_short)
self.loadSweep.clicked.connect(self.sweep_load)
self.dutSweep.clicked.connect(self.sweep_dut)
self.s1pButton.clicked.connect(self.write_s1p)
self.startValue.valueChanged.connect(self.set_start)
self.stopValue.valueChanged.connect(self.set_stop)
self.sizeValue.valueChanged.connect(self.set_size)
self.openPlot.clicked.connect(self.plot_open)
self.shortPlot.clicked.connect(self.plot_short)
self.loadPlot.clicked.connect(self.plot_load)
self.dutPlot.clicked.connect(self.plot_dut)
self.smithPlot.clicked.connect(self.plot_smith)
self.impPlot.clicked.connect(self.plot_imp)
self.rcPlot.clicked.connect(self.plot_rc)
self.swrPlot.clicked.connect(self.plot_swr)
self.rlPlot.clicked.connect(self.plot_rl)
# create timer
self.startTimer = QTimer(self)
self.startTimer.timeout.connect(self.timeout)
def start(self):
if self.idle:
self.connectButton.setEnabled(False)
self.socket.connectToHost(self.addrValue.text(), 1001)
self.startTimer.start(5000)
else:
self.stop()
def stop(self):
self.idle = True
self.socket.abort()
self.offset = 0
self.connectButton.setText('Connect')
self.connectButton.setEnabled(True)
self.sweepFrame.setEnabled(False)
self.selectFrame.setEnabled(True)
self.dutSweep.setEnabled(False)
def timeout(self):
self.display_error('timeout')
def connected(self):
self.startTimer.stop()
self.idle = False
self.set_start(self.startValue.value())
#.........这里部分代码省略.........
示例4: PulsedNMR
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import actions [as 别名]
class PulsedNMR(QMainWindow, Ui_PulsedNMR):
rates = {0:25.0e3, 1:50.0e3, 2:250.0e3, 3:500.0e3, 4:2500.0e3}
def __init__(self):
super(PulsedNMR, self).__init__()
self.setupUi(self)
self.rateValue.addItems(['25', '50', '250', '500', '2500'])
# IP address validator
rx = QRegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
self.addrValue.setValidator(QRegExpValidator(rx, self.addrValue))
# state variable
self.idle = True
# number of samples to show on the plot
self.size = 50000
# buffer and offset for the incoming samples
self.buffer = bytearray(8 * self.size)
self.offset = 0
# create figure
figure = Figure()
figure.set_facecolor('none')
self.axes = figure.add_subplot(111)
self.canvas = FigureCanvas(figure)
self.plotLayout.addWidget(self.canvas)
# create navigation toolbar
self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False)
# remove subplots action
actions = self.toolbar.actions()
self.toolbar.removeAction(actions[7])
self.plotLayout.addWidget(self.toolbar)
# create TCP socket
self.socket = QTcpSocket(self)
self.socket.connected.connect(self.connected)
self.socket.readyRead.connect(self.read_data)
self.socket.error.connect(self.display_error)
# connect signals from buttons and boxes
self.startButton.clicked.connect(self.start)
self.freqValue.valueChanged.connect(self.set_freq)
self.awidthValue.valueChanged.connect(self.set_awidth)
self.deltaValue.valueChanged.connect(self.set_delta)
self.rateValue.currentIndexChanged.connect(self.set_rate)
# set rate
self.rateValue.setCurrentIndex(2)
# create timer for the repetitions
self.timer = QTimer(self)
self.timer.timeout.connect(self.fire)
def start(self):
if self.idle:
self.startButton.setEnabled(False)
self.socket.connectToHost(self.addrValue.text(), 1001)
else:
self.idle = True
self.timer.stop()
self.socket.close()
self.offset = 0
self.startButton.setText('Start')
self.startButton.setEnabled(True)
def connected(self):
self.idle = False
self.set_freq(self.freqValue.value())
self.set_rate(self.rateValue.currentIndex())
self.set_awidth(self.awidthValue.value())
self.fire()
self.timer.start(self.deltaValue.value())
self.startButton.setText('Stop')
self.startButton.setEnabled(True)
def read_data(self):
size = self.socket.bytesAvailable()
if self.offset + size < 8 * self.size:
self.buffer[self.offset:self.offset + size] = self.socket.read(size)
self.offset += size
else:
self.buffer[self.offset:8 * self.size] = self.socket.read(8 * self.size - self.offset)
self.offset = 0
# plot the signal envelope
data = np.frombuffer(self.buffer, np.complex64)
self.curve.set_ydata(np.abs(data))
self.canvas.draw()
def display_error(self, socketError):
if socketError == QAbstractSocket.RemoteHostClosedError:
pass
else:
QMessageBox.information(self, 'PulsedNMR', 'Error: %s.' % self.socket.errorString())
self.startButton.setText('Start')
self.startButton.setEnabled(True)
def set_freq(self, value):
if self.idle: return
self.socket.write(struct.pack('<I', 0<<28 | int(1.0e6 * value)))
def set_rate(self, index):
# time axis
rate = float(PulsedNMR.rates[index])
time = np.linspace(0.0, (self.size - 1) * 1000.0 / rate, self.size)
# reset toolbar
self.toolbar.home()
self.toolbar._views.clear()
self.toolbar._positions.clear()
#.........这里部分代码省略.........
示例5: Scanner
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import actions [as 别名]
class Scanner(QMainWindow, Ui_Scanner):
def __init__(self):
super(Scanner, self).__init__()
self.setupUi(self)
# IP address validator
rx = QRegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
self.addrValue.setValidator(QRegExpValidator(rx, self.addrValue))
# state variable
self.idle = True
# number of samples to show on the plot
self.size = 512 * 512
self.freq = 143.0
# buffer and offset for the incoming samples
self.buffer = bytearray(8 * self.size)
self.offset = 0
self.data = np.frombuffer(self.buffer, np.int32)
# create figure
figure = Figure()
figure.set_facecolor('none')
self.axes = figure.add_subplot(111)
self.canvas = FigureCanvas(figure)
self.plotLayout.addWidget(self.canvas)
self.axes.axis((0.0, 512.0, 0.0, 512.0))
x, y = np.meshgrid(np.linspace(0.0, 512.0, 513), np.linspace(0.0, 512.0, 513))
z = x / 512.0 + y * 0.0
self.mesh = self.axes.pcolormesh(x, y, z, cmap = cm.plasma)
# create navigation toolbar
self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False)
# remove subplots action
actions = self.toolbar.actions()
if int(matplotlib.__version__[0]) < 2:
self.toolbar.removeAction(actions[7])
else:
self.toolbar.removeAction(actions[6])
self.plotLayout.addWidget(self.toolbar)
# create TCP socket
self.socket = QTcpSocket(self)
self.socket.connected.connect(self.connected)
self.socket.readyRead.connect(self.read_data)
self.socket.error.connect(self.display_error)
# connect signals from buttons and boxes
self.connectButton.clicked.connect(self.start)
self.scanButton.clicked.connect(self.scan)
self.periodValue.valueChanged.connect(self.set_period)
self.trgtimeValue.valueChanged.connect(self.set_trgtime)
self.trginvCheck.stateChanged.connect(self.set_trginv)
self.shdelayValue.valueChanged.connect(self.set_shdelay)
self.shtimeValue.valueChanged.connect(self.set_shtime)
self.shinvCheck.stateChanged.connect(self.set_shinv)
self.acqdelayValue.valueChanged.connect(self.set_acqdelay)
self.samplesValue.valueChanged.connect(self.set_samples)
self.pulsesValue.valueChanged.connect(self.set_pulses)
# create timers
self.startTimer = QTimer(self)
self.startTimer.timeout.connect(self.timeout)
self.meshTimer = QTimer(self)
self.meshTimer.timeout.connect(self.update_mesh)
# set default values
self.periodValue.setValue(200.0)
def start(self):
if self.idle:
self.connectButton.setEnabled(False)
self.socket.connectToHost(self.addrValue.text(), 1001)
self.startTimer.start(5000)
else:
self.stop()
def stop(self):
self.idle = True
self.socket.abort()
self.offset = 0
self.connectButton.setText('Connect')
self.connectButton.setEnabled(True)
self.scanButton.setEnabled(True)
def timeout(self):
self.display_error('timeout')
def connected(self):
self.startTimer.stop()
self.idle = False
self.set_period(self.periodValue.value())
self.set_trgtime(self.trgtimeValue.value())
self.set_trginv(self.trginvCheck.checkState())
self.set_shdelay(self.shdelayValue.value())
self.set_shtime(self.shtimeValue.value())
self.set_shinv(self.shinvCheck.checkState())
self.set_acqdelay(self.acqdelayValue.value())
self.set_samples(self.samplesValue.value())
self.set_pulses(self.pulsesValue.value())
# start pulse generators
self.socket.write(struct.pack('<I', 9<<28))
self.connectButton.setText('Disconnect')
self.connectButton.setEnabled(True)
self.scanButton.setEnabled(True)
def read_data(self):
size = self.socket.bytesAvailable()
if self.offset + size < 8 * self.size:
#.........这里部分代码省略.........