本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.update方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.update方法的具体用法?Python FigureCanvasQTAgg.update怎么用?Python FigureCanvasQTAgg.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FigureWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
class FigureWidget(QtGui.QWidget):
""" A QWidget that contains a matplotlib plot that plots a matrix as a
series of line plots.
"""
def __init__(self, parent=None):
super(FigureWidget, self).__init__(parent)
self.fig = plt.Figure()
self.setMinimumSize(500,300)
self.canvas = FigureCanvasQTAgg(self.fig)
self.canvas.setParent(self)
self.create_plots(1)
# set the plot background color to the window background color
color = QtGui.QPalette().window().color()
self.fig.set_facecolor((color.redF(), color.greenF(), color.blueF()))
self.canDraw = True
def create_plots(self, num_plots):
""" Create enough subplots to hold `num_plots` plots. """
self.canDraw = False
self.fig.clear()
self.axes = [self.fig.add_subplot(1,num_plots,n+1)
for n in range(num_plots)]
self.lines = [ax.plot(numpy.zeros(1024))[0] for ax in self.axes]
for ax in self.axes:
ax.set_ylim((-1,1))
ax.set_xlim((0,1024))
# move the spines out of the plot araea so it won't get
# clobbered by the partial redrawing during `self.draw()`.
ax.spines['bottom'].set_position(('outward', 5))
ax.spines['left'].set_position(('outward', 5))
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
self.fig.tight_layout()
self.canvas.draw()
self.canDraw = True
def resizeEvent(self, event):
""" Scale the figure in tandem with the widget. """
self.fig.set_size_inches(self.width()/80, self.height()/80)
self.canvas.draw()
def showEvent(self, event):
""" Called on the first draw. Sets up the correct window geometry. """
self.resizeEvent(None)
def draw(self, data):
""" Update the plots as quickly as possible. """
if not self.canDraw: return()
for n in range(data.shape[1]):
self.lines[n].set_ydata(data[:,n])
self.axes[n].draw_artist(self.axes[n].patch)
self.axes[n].draw_artist(self.lines[n])
self.canvas.update()
示例2: mpl_widget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
class mpl_widget(QWidget):
def __init__(self, parent=None, mainWidget=None):
self._SELECTEDCELLS = list() # container for instances of selected cells, so we can delete them when we want
self._SELECTEDCELLS_IJ = list() # container for coords of selected cells, so we can delete them when we want
self._SELECTEDCELLLINES = list() # container for instances of selected cells, so we can delete them when we want
self._GRIDLINES = None
QWidget.__init__(self, parent)
self.mainWidget = mainWidget
self.create_main_frame()
self.mpl_menu = mpl_menu(self)
self.shift_is_held = False
#self.connect(self.mpl_menu, QtCore.SIGNAL('mySignal'), self.mySlot)
#print 'my parent is:', parent
self.clear_selection()
self.init_tooltips()
def init_tooltips(self):
self.canvas.setToolTip('If 2D plot => RMB click toggles menu <br> - RMB click selects cell <br> - selected cells are drawn with black border')
self.grid_cb.setToolTip('If 2D plot => show computational grid <br> If 1D plot => show normal gridlines')
self.cbar_button.setToolTip('If 2D plot => controls the color range. <br> Note: <br> - pressing UP and DOWN arrows cycles through colormaps <br> - dragging colorbar with RMB scales the color-range <br> - dragging colorbar with LMB shifts the color-range')
self.mpl_toolbar.setToolTip('Shows coordinates (i,j, lat,lon) and data-value(z) under the cursor. <br> if you see <i>>>></i> coordinates are not visible. Enlarge the window')
def create_main_frame(self):
self.fig = Figure(dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.canvas.setFocusPolicy( Qt.ClickFocus )
self.canvas.setFocus()
self.mpl_toolbar = myNavigationToolbar(self.canvas, self)
self.canvas.mpl_connect('button_press_event', self.on_click)
self.canvas.mpl_connect('key_press_event', self.on_key_press)
self.canvas.mpl_connect('key_release_event', self.on_key_release)
#self.canvas.mpl_connect('button_press_event', self.disable_clicks)
self.cbar_button = QPushButton("Color Range")
self.cbar_button.setFocusPolicy( Qt.NoFocus )
self.grid_cb = QCheckBox("Show Grid")
self.grid_cb.setFocusPolicy( Qt.NoFocus )
self.grid_cb.stateChanged.connect(self.showGrid)
vbox = QVBoxLayout()
hbox = QHBoxLayout()
vbox.addWidget(self.canvas) # the matplotlib canvas
hbox.addWidget(self.mpl_toolbar)
hbox.addWidget(self.cbar_button)
hbox.addWidget(self.grid_cb)
vbox.addLayout(hbox)
self.setLayout(vbox)
def on_click(self, event):
if event.inaxes != self.get_axes()[0]: return
#if self.get_axes()[0].format_coord(event.x, event.y) == 'outside data area': return
if self.allow_menu():
self.allow_popup_menu = True
if self.shift_is_held:
self.allow_popup_menu = False
point = [int(event.xdata + .5), int(event.ydata + .5)]
#print '>>>', point, '\t currently {0} selected'.format(len(self._SELECTEDCELLS))
if event.button == 3 : #if RMB is clicked
# working with dialog for transect!
if self.mainWidget.transect_dlg:
if self.mainWidget.transect_dlg.toogle_show_after_selected_cell:
realx, realy = self.get_real_xy(event.xdata, event.ydata, self.mainWidget.detect_variable_dimensions())
realpoint = [realy, realx]
#print 'real xy:', realpoint
if self.mainWidget.transect_dlg.toogle_show_after_selected_cell == 1: # select point 1
self.allow_popup_menu = False
self.mainWidget.transect_dlg.data.set_p1(realpoint)
elif self.mainWidget.transect_dlg.toogle_show_after_selected_cell == 2: # select point 2
self.allow_popup_menu = False
self.mainWidget.transect_dlg.data.set_p2(realpoint)
self.mainWidget.transect_dlg.update()
self.mainWidget.transect_dlg.show()
# working with dialog for flux!
if self.mainWidget.flux_dlg:
if self.mainWidget.flux_dlg.toogle_show_after_selected_cell:
if self.mainWidget.flux_dlg.toogle_show_after_selected_cell == 1: # select point 1
self.allow_popup_menu = False
self.mainWidget.flux_dlg.data.set_p1(point)
elif self.mainWidget.flux_dlg.toogle_show_after_selected_cell == 2: # select point 2
self.allow_popup_menu = False
self.mainWidget.flux_dlg.data.set_p2(point)
self.mainWidget.flux_dlg.update()
self.mainWidget.flux_dlg.show()
if len(self._SELECTEDCELLS) == 0: # if no cell is selected
self.add_selected_cell(point)
#.........这里部分代码省略.........
示例3: mGraph
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
#.........这里部分代码省略.........
self.allButton.hide()
self.matframe.hide()
self.matPlotInfo.hide()
self.toolbarFrame.hide()
layout = QtGui.QVBoxLayout()
layout.addLayout(buttonLayout)
layout.addLayout(buttonLayout2)
layout.addLayout(buttonLayout3)
layout.addWidget(self.matPlotInfo)
layout.addWidget(self.matframe)
layout.addWidget(self.toolbarFrame)
self.setLayout(layout)
def enableAutoScaling(self):
self.timer.start(self.refreshRateSec * 1000)
# self.canvas.mpl_disconnect(self.cid)
# self.cid = self.canvas.mpl_connect('button_press_event', self.disableAutoScaling)
self.home = True
self.matPlotInfo.hide()
# self.deviceThread = threading.Thread(target =
# self.plot, args=[self.currTimeRange])
# If the main thread stops, stop the child thread
# self.deviceThread.daemon = True
# Start the thread
# self.deviceThread.start()
self.plot(self.currTimeRange)
def disableAutoScaling(self, event):
self.home = False
self.matPlotInfo.show()
self.canvas.update()
# plt.show()
# print event.name
# self.canvas.mpl_disconnect(self.cid)
# self.cid = self.canvas.mpl_connect('button_press_event', self.enableAutoScaling)
self.timer.stop()
# self.zoom(self.toolbar)
def togglePlot(self):
if not self.hidden:
self.canvas.hide()
self.toolbar.hide()
self.thrtysecButton.hide()
self.twoMinButton.hide()
self.fiveMinButton.hide()
self.thrtyMinButton.hide()
self.twoHrButton.hide()
self.tenHrButton.hide()
self.oneDayButton.hide()
self.oneWkButton.hide()
self.twoWkButton.hide()
self.allButton.hide()
self.matPlotInfo.hide()
self.matframe.hide()
self.toolbarFrame.hide()
self.timer.stop()
self.hideButton.setText("Show Plot")
self.hidden = True
elif self.hidden:
self.canvas.show()
self.toolbar.show()
示例4: Window
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
#.........这里部分代码省略.........
m = 59
s = 59
else:
self.timer.stop()
time1 = ("{0}:{1}:{2}".format(h,m,s))
self.Alarm()
self.HLT_Timer_DISPLAY.setDigitCount(len(time1))
self.HLT_Timer_DISPLAY.display(time1)
#Sets boil timer
def Set2(self):
global t2,h2,m2,s2
t2 = self.BOIL_TIMER_SET.time()
self.BOIL_TIMER_DISPLAY.display(t2.toString())
self.timer2.start(1000)
h2 = t2.hour()
m2 = t2.minute()
s2 = t2.second()
#timer for boil timer(counts the timer down)
def Time2(self):
global t2,h2,m2,s2,time2
if s2 > 0:
s2 -= 1
else:
if m2 > 0:
m2 -= 1
s2 = 59
elif m2 == 0 and h2 > 0:
h2 -= 1
m2 = 59
s2 = 59
else:
self.timer2.stop()
time2 = ("{0}:{1}:{2}".format(h2,m2,s2))
self.Alarm()
self.BOIL_TIMER_DISPLAY.setDigitCount(len(time2))
self.BOIL_TIMER_DISPLAY.display(time2)
#checks to see if alarm has been triggered and sets gpio 18 to high
def Alarm(self):
global alarm1,alarm2,time1,time2
for x, y in alarm1.iteritems():
if x.isChecked():
a = y.time()
h = a.hour()
m = a.minute()
s = a.second()
time4 = ("{0}:{1}:{2}".format(h,m,s))
if time4 == time1:
print "ALARM 1 ACTIVE"
os.system('sh -c "echo low > /sys/class/gpio/gpio18/direction"')
for x, y in alarm2.iteritems():
if x.isChecked():
a = y.time()
h = a.hour()
m = a.minute()
s = a.second()
time4 = ("{0}:{1}:{2}".format(h,m,s))
if time4 == time2:
print "ALARM 2 ACTIVE"
os.system('sh -c "echo high > /sys/class/gpio/gpio18/direction"')
#displays temps by calling settemp from temprature.py
def display_temp(self):
temp = sent_temp()
self.HLT_TEMP.display(temp[0])
self.MASH_TEMP.display(temp[1])
self.Boil_TEMP.display(temp[2])
#creates a graph and displays it
def plot(self):
temp = sent_temp()
temp1.append(temp[0])
temp2.append(temp[1])
temp3.append(temp[2])
M1.append(m3)
XHLT= self.figure.add_subplot(111)
XHLT.plot(M1,temp1,'b-',label = "HLT")
XHLT.plot(M1,temp2,'r-',label = "MASH")
XHLT.plot(M1,temp3,'g-',label = "BOIL")
self.canvas.draw()
self.canvas.update()
if m3 == 0 and h3 == 0 and s3 == 0:
XHLT.hold(False)
示例5: update
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
def update(self):
self.fig.tight_layout()
FigureCanvas.update(self)
示例6: InteractiveVelocityPlot
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import update [as 别名]
#.........这里部分代码省略.........
self.previous_keypress = None
self.previous_wavelength = None
# Set up the key-press events:
self.canvas.mpl_connect('key_press_event', self.on_keypress)
# Set the main frame as the central widget:
self.window.setCentralWidget(self.main_frame)
# Resize the window so it will display the canvas with the
# requested size:
layout_height = vbox.sizeHint().height()
layout_width = vbox.sizeHint().width()
status_bar_height = self.window.statusBar().sizeHint().height()
height = layout_height + status_bar_height
self.window.resize(layout_width, height)
# Re-do labels:
del self.texts[:]
self.text(0.45, 0.02, 'Velocity offset (km s$^{-1}$)')
self.text(0.01, 0.57, 'Transmission', rotation=90)
# Disable any existing callbacks:
self.cids = dict()
cids1 = list(self.canvas.callbacks.callbacks['key_press_event'])
cids2 = list(self.canvas.callbacks.callbacks['button_press_event'])
cids = cids1 + cids2
for cid in cids:
self.canvas.callbacks.disconnect(cid)
# Connect new callbacks:
self.connect()
def update_plot(self, redshift):
# Restore background regions:
[self.canvas.restore_region(background)
for background in self.backgrounds]
# Plot data:
[data.pop(0).remove() for data in self.data]
self.plot_data(
self.wavelength, self.flux, self.error, self.continuum,
redshift, **self.options['DATA'])
# Draw the artists:
for artists in self.data:
for element in artists:
ax = element.get_axes()
ax.draw_artist(element)
# Plot the models (if any):
if self.options['MODEL']['absorbers'] is not None:
self.plot_models(resolution=self.resolution,
convolve_with_cos_fuv=self.cos_fuv,
convolve_with_cos_nuv=self.cos_nuv,
**self.options['MODEL'])
# Draw the artists:
for artists in self.models:
for element in artists:
ax = element.get_axes()
ax.draw_artist(element)
# Draw new panel labels:
for i, transition in enumerate(self.transitions):