本文整理汇总了Python中matplotlib.figure.Figure.hold方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.hold方法的具体用法?Python Figure.hold怎么用?Python Figure.hold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.hold方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_canvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
def setup_canvas(remote):
"""
Setup the canvas, for use by the other functions that popluate it with
plots.
"""
global f, canvas, degreeChar, num_plots
degreeChar = u'\N{DEGREE SIGN}'
num_plots = 38
plot_height = 200
f = Figure(dpi=100)
f.hold(False)
if remote == True:
canvas = FigureCanvasGTK(f) # a gtk.DrawingArea
else:
canvas = FigureCanvasGTKAgg(f) # a gtk.DrawingArea
# the size request sets the size of the area for the plots. Second number is the height
canvas.set_size_request(800, num_plots * plot_height)
app.viewport_matplotlib.add(canvas)
canvas.show()
示例2: Grinder
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
class Grinder(QMainWindow):
def __init__(self, metaData, parent=None):
# Metadata into properties
# self.analystName = metaData['analystName']
self.analystName = metaData['analystName']
self.expDate = metaData['expDate']
self.expName = metaData['expName']
self.rawData = metaData['rawData']
self.patientName = metaData['patientName']
self.sideTested = metaData['sideTested']
self.movementType = metaData['movementType']
self.uuidId = metaData['uuidId']
# self.gammaDyn = gammaDyn
# self.gammaSta = gammaSta
# Some useful stuff
self.allEndLines = []
self.iBegins = []
self.iEnds = []
self.currEndLine = None
self.currEndLineId = None
self.baseChannel = 'Left Elbow Flex / Time'
self.isDragging = False
QMainWindow.__init__(self, parent)
# self.showMaximized()
self.createMainFrame()
self.setNumTrials()
def createMainFrame(self):
self.main_frame = QWidget()
self.fig = Figure((5.0, 4.0), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self.main_frame)
self.canvas.setFocusPolicy(Qt.StrongFocus)
self.canvas.setFocus()
self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
self.canvas.mpl_connect('key_press_event', self.onKey)
self.canvas.mpl_connect('pick_event', self.onPick)
self.canvas.mpl_connect('button_press_event', self.onMouseDown)
self.canvas.mpl_connect('button_release_event', self.onMouseUp)
self.canvas.mpl_connect('motion_notify_event', self.onMouseMotion)
# Initial draw
self.fig.clear()
self.fig.hold(True)
self.ax = self.fig.add_subplot(111)
self.ax.plot(self.rawData[self.baseChannel])
# Other GUI controls
#
self.numTrialBox = QSpinBox()
self.numTrialBox.setMinimum(1)
self.numTrialBox.setValue(1)
self.numTrialBox.setMinimumWidth(200)
self.connect(self.numTrialBox, SIGNAL('valueChanged(int)'), self.onNumTrialBox)
self.submitButton = QPushButton("&Submit")
self.connect(self.submitButton, SIGNAL('clicked()'), self.onSubmit)
self.grid_cb = QCheckBox("Show &Grid")
self.grid_cb.setChecked(False)
self.connect(self.grid_cb, SIGNAL('stateChanged(int)'), self.onGrid)
slider_label = QLabel('Bar width (%):')
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(1, 100)
self.slider.setValue(20)
self.slider.setTracking(True)
self.slider.setTickPosition(QSlider.TicksBothSides)
self.connect(self.slider, SIGNAL('valueChanged(int)'), self.onSlider)
#
# Layout with box sizers
#
hbox = QHBoxLayout()
for w in [self.numTrialBox, self.submitButton, self.grid_cb,
slider_label, self.slider]:
hbox.addWidget(w)
hbox.setAlignment(w, Qt.AlignVCenter)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
def setEndLine(self, new_x):
minLen = 50
if self.currEndLineId > 0:
leftx, lefty = self.allEndLines[self.currEndLineId - 1].get_data()
lbound = leftx[0] + minLen
#.........这里部分代码省略.........
示例3: MatplotDisplay
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
class MatplotDisplay(gpi.GenericWidgetGroup):
"""Embeds the matplotlib figure window.
"""
valueChanged = gpi.Signal()
def __init__(self, title, parent=None):
super(MatplotDisplay, self).__init__(title, parent)
# gpi interface
self._collapsables = []
self._subplotSettings = {}
#self._subplotPosition = {'right': 0.9, 'bottom': 0.12, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2, 'left': 0.125}
self._subplotPosition = {'right': 0.913, 'bottom': 0.119, 'top': 0.912, 'wspace': 0.2, 'hspace': 0.2, 'left': 0.111}
#self._subplot_keepers = ['yscale', 'xscale'] # linear, log
self._subplot_keepers = []
self._lineSettings = []
self._line_keepers = ['linewidth', 'linestyle', 'label', 'marker', 'markeredgecolor', 'markerfacecolor', 'markersize', 'color', 'alpha']
# since drawing is slow, don't do it as often, use the timer as a
# debouncer
self._on_draw_cnt = 0
self._updatetimer = QtCore.QTimer()
self._updatetimer.setSingleShot(True)
self._updatetimer.timeout.connect(self._on_draw)
self._updatetimer.setInterval(10)
# plot specific UI side panel
# -sets options for plot window so this needs to be run first
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0) # no spaces around this item
vbox.setSpacing(0)
# AUTOSCALE
self._autoscale_btn = gpi.widgets.BasicPushButton(self)
self._autoscale_btn.set_toggle(True)
self._autoscale_btn.set_button_title('autoscale')
self._autoscale_btn.valueChanged.connect(self.on_draw)
self._collapsables.append(self._autoscale_btn)
# GRID
self._grid_btn = gpi.widgets.BasicPushButton(self)
self._grid_btn.set_toggle(True)
self._grid_btn.set_button_title('grid')
self._grid_btn.valueChanged.connect(self.on_draw)
self._collapsables.append(self._grid_btn)
# X/Y LIMITS
lims = QtGui.QGridLayout()
self._xl = gpi.widgets.BasicDoubleSpinBox(self)
self._xh = gpi.widgets.BasicDoubleSpinBox(self)
self._yl = gpi.widgets.BasicDoubleSpinBox(self)
self._yh = gpi.widgets.BasicDoubleSpinBox(self)
self._xl.valueChanged.connect(self.on_draw)
self._xh.valueChanged.connect(self.on_draw)
self._yl.valueChanged.connect(self.on_draw)
self._yh.valueChanged.connect(self.on_draw)
self._xl.set_immediate(True)
self._xh.set_immediate(True)
self._yl.set_immediate(True)
self._yh.set_immediate(True)
self._xl.set_label('max')
self._xh.set_label('min')
self._xl.set_decimals(7)
self._xh.set_decimals(7)
self._yl.set_decimals(7)
self._yh.set_decimals(7)
self._xlab = QtGui.QLabel('x limits')
self._ylab = QtGui.QLabel('y limits')
#self._maxlab = QtGui.QLabel('max')
#self._minlab = QtGui.QLabel('min')
#lims.addWidget(self._maxlab,1,0,1,1)
#lims.addWidget(self._minlab,2,0,1,1)
lims.addWidget(self._xlab,0,1,1,1,alignment=QtCore.Qt.AlignHCenter)
lims.addWidget(self._xh,1,1,1,1,alignment=QtCore.Qt.AlignHCenter)
lims.addWidget(self._xl,2,1,1,1,alignment=QtCore.Qt.AlignHCenter)
lims.addWidget(self._ylab,0,2,1,1,alignment=QtCore.Qt.AlignHCenter)
lims.addWidget(self._yh,1,2,1,1,alignment=QtCore.Qt.AlignHCenter)
lims.addWidget(self._yl,2,2,1,1,alignment=QtCore.Qt.AlignHCenter)
self._collapsables.append(self._xlab)
self._collapsables.append(self._ylab)
self._collapsables.append(self._xl)
self._collapsables.append(self._xh)
self._collapsables.append(self._yl)
self._collapsables.append(self._yh)
#self._collapsables.append(self._minlab)
#self._collapsables.append(self._maxlab)
# TICK MARKS
ticks = QtGui.QGridLayout()
self._x_numticks = gpi.widgets.BasicSpinBox(self)
self._x_numticks.valueChanged.connect(self.on_draw)
self._y_numticks = gpi.widgets.BasicSpinBox(self)
self._y_numticks.valueChanged.connect(self.on_draw)
self._x_ticks = QtGui.QLineEdit()
self._y_ticks = QtGui.QLineEdit()
self._x_ticks.textChanged.connect(lambda txt: self.check_validticks(self._x_ticks))
self._y_ticks.textChanged.connect(lambda txt: self.check_validticks(self._y_ticks))
self._x_ticks.setPlaceholderText('comma separated list of x labels')
self._y_ticks.setPlaceholderText('comma separated list of y labels')
#.........这里部分代码省略.........
示例4: MatplotDisplay2
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
class MatplotDisplay2(gpi.GenericWidgetGroup):
valueChanged = gpi.Signal()
def __init__(self, title, parent=None):
super(MatplotDisplay2, self).__init__(title, parent)
#self.data = self.get_data2()
self._data = None
self.create_main_frame()
self.on_draw()
# setters
def set_val(self, data):
'''Takes a list of npy arrays.
'''
if isinstance(data, list):
self._data = data
self.on_draw()
else:
return
# getters
def get_val(self):
return self._data
# support
def create_main_frame(self):
self.fig = Figure((5.0, 4.0), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
self.canvas.setFocus()
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
self.canvas.mpl_connect('key_press_event', self.on_key_press)
vbox = QtGui.QVBoxLayout()
vbox.addWidget(self.canvas) # the matplotlib canvas
vbox.addWidget(self.mpl_toolbar)
self.setLayout(vbox)
def get_data2(self):
return np.arange(20).reshape([4, 5]).copy()
def on_draw(self):
self.fig.clear()
self.axes = self.fig.add_subplot(111)
# self.axes.plot(self.x, self.y, 'ro')
# self.axes.imshow(self.data, interpolation='nearest')
# self.axes.plot([1,2,3])
if self._data is None:
return
self.fig.hold(True)
# plot each set
# print "--------------------plot the data"
for data in self._data:
# check for x, y data
if data.shape[-1] == 2:
self.axes.plot(data[..., 0], data[..., 1], alpha=0.8, lw=2.0)
else:
self.axes.plot(data, alpha=0.8, lw=2.0)
self.canvas.draw()
def on_key_press(self, event):
# print 'Matplotlib-> you pressed:' + str(event.key)
# implement the default mpl key press events described at
# http://matplotlib.org/users/navigation_toolbar.html#navigation-
# keyboard-shortcuts
try:
from matplotlib.backend_bases import key_press_handler
key_press_handler(event, self.canvas, self.mpl_toolbar)
except:
print("key_press_handler import failed. -old matplotlib version.")
示例5: Watcher
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
#.........这里部分代码省略.........
self.isAcceptedCB.setChecked(False)
self.connect(self.isAcceptedCB, SIGNAL('stateChanged(int)'), self.onChangeIsAccepted)
slider_label = QLabel('Bar width (%):')
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(1, 100)
self.slider.setValue(20)
self.slider.setTracking(True)
self.slider.setTickPosition(QSlider.TicksBothSides)
# self.connect(self.slider, SIGNAL('valueChanged(int)'), self.onSlider)
#
# Layout with box sizers
#
hbox = QHBoxLayout()
for w in [self.textbox, self.queryButton,self.isAcceptedCB,
self.bwdButton, self.fwdButton, self.alignButton,
self.grid_cb, slider_label, self.slider]:
hbox.addWidget(w)
hbox.setAlignment(w, Qt.AlignVCenter)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
def drawCurrTrial(self):
self.fig.clear()
self.fig.hold(True)
self.ax1 = self.fig.add_subplot(211)
self.ax2 = self.fig.add_subplot(212)
self.ax1.plot(self.currTrial['Left Shoulder Flex / Time'])
self.ax1.set_ylim([20, 120])
self.ax2.plot(self.currTrial['Biceps'])
self.ax2.set_ylim([-1.0, 1.0])
### Draw timeOnset lines
self.onsetLine1 = self.ax1.axvline(x=self.currOnset(), ymin=0, ymax=100, color='b', linewidth=5)
self.onsetLine2 = self.ax2.axvline(x=self.currOnset(), ymin=0, ymax=100, color='r', linewidth=5)
self.canvas.draw()
def currOnset(self):
return self.allQueryResults[self.idList[self.currTrialNum]]['timeOnset']
def setOnset(self):
"""Add the field 'onset' to all documents"""
l = self.currTrial['Left Shoulder Flex / Time'][0:800]
base = sum(l) / float(len(l))
th = base * 0.98
f = lambda x: x <= th
possible = indices(f, self.currTrial['Left Shoulder Flex / Time'])
tOnset = possible[0]
self.allOnsets[self.currTrialNum] = tOnset
self.allQueryResults[self.idList[self.currTrialNum]]['timeOnset'] = int(tOnset)
# self.allAlignedTrials[self.currTrialNum] = self.currTrial.drop(xrange(self.currOnset - 100))
示例6: ResidualPlot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
class ResidualPlot(FigureCanvas):
__instance = None
def __init__(self):
Global.event.task_selected.connect(self._on_task_selected)
Global.event.plot_x_limit_changed.connect(self._on_x_limit_changed)
Global.event.task_deleted.connect(self._on_task_deleted)
Global.event.tasks_list_updated.connect(self._on_tasks_list_updated)
self.task = None
self.axes = None
self.last_x_limit = []
self.chi2s = []
bg_color = str(QPalette().color(QPalette.Active, QPalette.Window).name())
rcParams.update({'font.size': 10})
self.figure = Figure(facecolor=bg_color, edgecolor=bg_color)
self.figure.hold(False)
super(ResidualPlot, self).__init__(self.figure)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.updateGeometry()
self.hide()
def _on_task_selected(self, task):
self.set_task(task)
self.redraw()
def _on_task_deleted(self, task):
if self.task == task:
self.set_task(None)
self.clear()
def _on_tasks_list_updated(self):
if not len(Global.tasks()):
self.set_task(None)
self.clear()
def set_task(self, task):
self.task = task
def clear(self):
self.figure.clf()
self.figure.clear()
self.draw()
self.parent().chi2_label.hide()
self.parent().chi2_value.hide()
self.hide()
gc.collect()
def redraw(self):
self.clear()
if self.task.result.chi2 is None:
self.parent().chi2_label.hide()
self.parent().chi2_value.hide()
self.hide()
return
self.chi2s.append(self.task.result.chi2)
self.show()
self.parent().chi2_label.show()
self.parent().chi2_value.show()
self.axes = self.figure.add_subplot(1, 1, 1)
self.axes.grid(False)
self.figure.set_alpha(0)
self.axes.set_xlabel('Phase')
self.axes.set_ylabel('Residual')
phases = []
delta_values = []
keys = sorted(self.task.result.data().keys())
for key in keys:
if self.task.result.data()[key]['delta_value'] is not None:
phases.append(key)
delta_values.append(self.task.result.data()[key]['delta_value'])
y_max = max(abs(min(delta_values)), abs(max(delta_values)))
y_pad = (y_max / 100) * 10
self.axes.set_autoscaley_on(False)
self.axes.set_ylim([-(y_max + y_pad), y_max + y_pad])
self.axes.set_autoscalex_on(False)
self.axes.set_xlim(self.last_x_limit)
color = QColor(0,0,0)
min_chi2 = min(self.chi2s)
if len(self.chi2s) == 1 :
color = QColor(0,0,0)
elif self.task.result.chi2 <= min_chi2 :
color = QColor(0,139,0)
else:
color = QColor(255,0,0)
#.........这里部分代码省略.........
示例7: Plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
class Plot(FigureCanvas):
__instance = None
def __init__(self):
Global.event.task_selected.connect(self._on_task_selected)
Global.event.task_deleted.connect(self._on_task_deleted)
Global.event.tasks_list_updated.connect(self._on_tasks_list_updated)
self.task = None
self.last_x_limit = []
self.axes = None
bg_color = str(QPalette().color(QPalette.Active, QPalette.Window).name())
rcParams.update({'font.size': 10})
self.figure = Figure(facecolor=bg_color, edgecolor=bg_color)
self.figure.hold(False)
super(Plot, self).__init__(self.figure)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.updateGeometry()
def _on_task_selected(self, task):
self.set_task(task)
self.redraw()
def _on_task_deleted(self, task):
if self.task == task:
self.set_task(None)
self.clear()
ResultTab.instance().set_data([], [], [], [])
def _on_tasks_list_updated(self):
if not len(Global.tasks()):
self.set_task(None)
self.clear()
ResultTab.instance().set_data([], [], [], [])
@staticmethod
def instance():
return Plot.__instance
def set_task(self, task):
self.task = task
def clear(self):
self.figure.clf()
self.figure.clear()
gc.collect()
def redraw(self):
self.clear()
self.axes = self.figure.add_subplot(1, 1, 1)
self.axes.grid(True)
self.axes.set_xlabel('Phase')
self.axes.set_ylabel('Flux')
result_phases = []
result_values = []
import_phases = []
import_values = []
keys = sorted(self.task.result.data().keys())
for key in keys:
if self.task.result.data()[key]['result_value'] is not None:
result_phases.append(key)
result_values.append(self.task.result.data()[key]['result_value'])
if self.task.result.data()[key]['import_value'] is not None:
import_phases.append(key)
import_values.append(self.task.result.data()[key]['import_value'])
ResultTab.instance().set_data(result_phases, result_values, import_phases, import_values)
if not result_phases and not import_phases :
return
y_r_min = 1
y_r_max = 0
x_r_max = 0
y_i_min = 1
y_i_max = 0
x_i_max = 0
if result_values :
y_r_min = min(result_values)
y_r_max = max(result_values)
x_r_max = max(abs(min(result_phases)), abs(max(result_phases)))
if import_values :
y_i_min = min(import_values)
y_i_max = max(import_values)
x_i_max = max(abs(min(import_phases)), abs(max(import_phases)))
y_max = max(y_r_max, y_i_max)
y_min = min(y_r_min, y_i_min)
x_max = max(x_r_max, x_i_max)
#.........这里部分代码省略.........
示例8: Watcher
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hold [as 别名]
#.........这里部分代码省略.........
self.connect(self.alignButton, SIGNAL('clicked()'), self.onFinish)
self.grid_cb = QCheckBox("Show &Grid")
self.grid_cb.setChecked(False)
# self.connect(self.grid_cb, SIGNAL('stateChanged(int)'), self.onGrid)
slider_label = QLabel('Bar width (%):')
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(1, 100)
self.slider.setValue(20)
self.slider.setTracking(True)
self.slider.setTickPosition(QSlider.TicksBothSides)
# self.connect(self.slider, SIGNAL('valueChanged(int)'), self.onSlider)
#
# Layout with box sizers
#
hbox = QHBoxLayout()
for w in [self.textbox, self.queryButton,
self.bwdButton, self.fwdButton, self.alignButton,
self.grid_cb, slider_label, self.slider]:
hbox.addWidget(w)
hbox.setAlignment(w, Qt.AlignVCenter)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
def drawCurrTrial(self):
self.fig.clear()
self.fig.hold(True)
self.ax1 = self.fig.add_subplot(211)
self.ax2 = self.fig.add_subplot(212)
self.ax1.plot(self.currTrial['musLce0'])
self.ax1.set_ylim([0.5, 1.5])
self.ax2.plot(self.currTrial['emg0'])
self.ax2.set_ylim([-6.0, 6.0])
self.canvas.draw()
def setOnsetLine(self):
maxL = 100
if self.onsetLine1 in self.ax1.lines:
self.ax1.lines.remove(self.onsetLine1)
if self.onsetLine2 in self.ax2.lines:
self.ax2.lines.remove(self.onsetLine2)
self.onsetLine1 = self.ax1.axvline(self.currOnset, 0, maxL, color='r')
self.onsetLine2 = self.ax2.axvline(self.currOnset, 0, maxL, color='r')
self.canvas.draw()
def setOnset(self):
"""Add the field 'onset' to all documents"""
l = self.currTrial.musLce0[0:100]
base = sum(l) / float(len(l))
th = base * 1.02
f = lambda i: self.currTrial.musLce0[i] <= th <= self.currTrial.musLce0[min(len(self.currTrial) - 1, i + 1)]
possible = filter(f, range(len(self.currTrial.musLce0)))
if possible:
self.currOnset = possible[0]
else:
self.currOnset = len(self.currTrial) / 2
self.allOnsets[self.currTrialId] = self.currOnset
self.allAlignedTrials[self.currTrialId] = self.currTrial.drop(xrange(self.currOnset - 100))
def setCurrTrial(self, n=0):
self.currTrialId = n
# print(len(self.allTrials))
self.currTrial = self.allTrials[self.currTrialId]
# print(self.currTrialId, len(self.currTrial))
def onFwd(self):
"""Go forward 1 trial"""
self.setCurrTrial(min(self.currTrialId + 1, self.numTrials - 1))
self.drawCurrTrial()
# self.setOnset()
# self.setOnsetLine()
def onBwd(self):
"""Go backward 1 trial"""
self.setCurrTrial(max(self.currTrialId - 1, 0))
self.drawCurrTrial()
# self.setOnset()
# self.setOnsetLine()
def onFinish(self):
# self.freezeAllOnsets()
self.close()
def onSubmit(self):
self.queryData(str(self.textbox.toPlainText()))
self.setCurrTrial()
self.drawCurrTrial()