本文整理汇总了Python中matplotlib.figure.Figure.close方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.close方法的具体用法?Python Figure.close怎么用?Python Figure.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import close [as 别名]
#.........这里部分代码省略.........
self.device = device
self.update_controls()
self.validate()
elif event.id == EVENT_ID_ONERROR:
if self._ui.onDecodeErrorComboBox.currentIndex() == HALT:
self.stop_recording()
self.show_message("ERROR: %s" % event.data)
else:
if not self.in_error:
self.in_error = True
self.show_message("ERROR: %s" % event.data)
else:
self.error_counts += 1
if self.error_counts > 5:
self.stop_recording()
self.show_message("Too many errors! %s" % event.data)
elif event.id == EVENT_ID_ONDISCONNECT:
self.recording_state = STATE_IDLE
self.show_message("Device id %d disconnected." % device.get_id())
self.shutdown()
elif event.id == EVENT_ID_ONREADDATA:
if analyzer is not None:
if self.recording_state == STATE_WAITING_FOR_FRAME:
if self.device.get_analyzer().first_valid_frame_received():
self.show_message("Recording. Press 'Stop' to stop recording.")
self.recording_state = STATE_RECORDING
elif event.id == EVENT_ID_ONANALYZERDATA:
if self.recording_state == STATE_RECORDING and \
self.current_expected_pcm_clock_rate is not None:
# Sanity check the sampling rate with the detected clock frequency
if analyzer is not None:
clock_period_samples = self.device.get_analyzer().get_average_clock_period_in_samples()
meas_clock_freq = self.device.get_sampling_rate_hz() / clock_period_samples
if (1.2 * self.current_expected_pcm_clock_rate) < meas_clock_freq or \
(0.8 * self.current_expected_pcm_clock_rate) > meas_clock_freq:
# The user's setup is probably wrong, so bail immediately
self.stop_recording()
self.show_message("Detected a PCM clock of ~%d Hz. Check your settings!" % meas_clock_freq)
self.analyzed_data_received_event.emit(event.data)
def update_plot(self, data):
if self.plot_background is None:
self.plot_background = self.plotCanvas.copy_from_bbox(self.fft_axis.bbox)
channel = self._ui.comboPCMChannelToListenTo.currentIndex()
channel_data = data[channel]
numpoints = len(channel_data)
if self.fft_line is None:
self.fft_line, = self.fft_axis.plot(numpy.zeros(numpoints), animated=True)
sampling_rate = int(self._ui.samplingRateLineEdit.text())
freqs = numpy.fft.fftfreq(numpoints * 2, d=1.0 / float(sampling_rate))
# Restore the clean slate background (this is the 'blit' method, which
# is much faster to render)
self.plotCanvas.restore_region(self.plot_background, bbox=self.fft_axis.bbox)
self.fft_line.set_ydata(channel_data)
self.fft_line.set_xdata(freqs[:numpoints])
# Draw the line
self.fft_axis.draw_artist(self.fft_line)
# Blit the canvas
self.plotCanvas.blit(self.fft_axis.bbox)
def reset(self,):
self.current_expected_pcm_clock_rate = None
if self.device is not None:
self.device.stop()
self.analyzer = None
self.realtime_timer.stop()
self.plot_timer.stop()
if self.play_sound_thread.isRunning():
self.play_sound_thread.quit()
self.play_sound_thread.wait()
self._ui.messagesLabel.setStyleSheet("background-color: none;")
self.error_ticks = 0
self.error_counts = 0
self.in_error = False
def shutdown(self,):
self.recording_state = STATE_IDLE
self.reset()
self.device = None
try:
self.figure.close()
except:
pass
def closeEvent(self, event):
"""Intercepts the close event of the MainWindow."""
self.show_message("Closing device...")
try:
self.shutdown()
self.event_listener.quit()
self.event_listener.wait()
self.audio.terminate()
finally:
super(MainWindow, self).closeEvent(event)