本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg类的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg类的具体用法?Python FigureCanvasQTAgg怎么用?Python FigureCanvasQTAgg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FigureCanvasQTAgg类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyPressEvent
def keyPressEvent(self, event):
if self.redetecter:
self.detecter()
key = event.key()
txt = event.text()
modifiers = event.modifiers()
accept = True
debug(u"key: ", key)
if key == Qt.Key_Delete and self.select:
if shift_down(event):
self.executer(u"%s.cacher()" %self.select.nom)
else:
self.executer(u"%s.supprimer()" %self.select.nom)
elif key in (Qt.Key_Return, Qt.Key_Enter) and self.editeur.objet is not self.select:
self.editer(shift_down(event))
elif self.editeur and not self.editeur.key(key, txt, modifiers):
accept = False
if key == Qt.Key_Escape and self.interaction:
print "ESCAPE !"
self.interaction(special="ESC")
accept = True
if not accept:
FigureCanvasQTAgg.keyPressEvent(self, event)
示例2: RewardWidget
class RewardWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(RewardWidget, self).__init__(parent)
self.samples = 0
self.resize(1500, 100)
self.figure = Figure()
self.canvas = FigureCanvasQTAgg(self.figure)
self.axes = self.figure.add_axes([0, 0, 1, 1])
self.layoutVertical = QtGui.QVBoxLayout(self)
self.layoutVertical.addWidget(self.canvas)
def set_time_range(self, time_range):
self.time_range = time_range
range_length = int((time_range[1] - time_range[0]))
self.rewards = [0] * (range_length * 100)
def add_data(self, data_range, data):
begin = int(round((data_range[0] - self.time_range[0]) * 100))
end = int(round((data_range[1] - self.time_range[0]) * 100)) + 1
self.rewards[begin:end] = [data for x in range(end-begin)]
range_length = int((self.time_range[1] - self.time_range[0]))
self.axes.clear()
self.axes.set_xlim([0,range_length*100])
self.axes.set_ylim([-10.0,10.0])
self.axes.plot(self.rewards)
self.canvas.draw()
#print(self.rewards)
示例3: MatplotlibWidget
class MatplotlibWidget(QtGui.QWidget):
"""
Implements a Matplotlib figure inside a QWidget.
Use getFigure() and redraw() to interact with matplotlib.
Example::
mw = MatplotlibWidget()
subplot = mw.getFigure().add_subplot(111)
subplot.plot(x,y)
mw.draw()
"""
def __init__(self, size=(5.0, 4.0), dpi=100):
QtGui.QWidget.__init__(self)
self.fig = Figure(size, dpi=dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.toolbar = NavigationToolbar(self.canvas, self)
self.vbox = QtGui.QVBoxLayout()
self.vbox.addWidget(self.toolbar)
self.vbox.addWidget(self.canvas)
self.setLayout(self.vbox)
def getFigure(self):
return self.fig
def draw(self):
self.canvas.draw()
示例4: __init__
def __init__(self, parent=None, width=5, height=4, dpi=72):
# fiugrueの生成
self.fig = Figure(figsize=(width, height), dpi=dpi,
facecolor=[0.5, 0.5, 0.5], edgecolor=None,
linewidth=1.0,
frameon=True, tight_layout=True)
# axesハンドルの生成
self.axes = self.fig.add_subplot(111)
# 再描画では上書きしない
self.axes.hold(False)
# 画像の初期表示
self.compute_initial_fiugre()
# コンストラクタ
FigureCanvas.__init__(self, self.fig)
# 親のウィジェットを生成
self.setParent(parent)
# サイズの設定
# FigureCanvas.setSizePolicy(self,
# QtGui.QSizePolicy.Expanding,
# QtGui.QSizePolicy.Expanding)
# サイズの更新
FigureCanvas.updateGeometry(self)
示例5: __init__
def __init__(self, spurset, fef, parent):
chart.__init__(self, spurset, fef, parent)
# make the figure blend in with the native application look
bgcol = parent.palette().window().color().toRgb()
bgcol = [bgcol.redF(), bgcol.greenF(), bgcol.blueF()]
self.fig = Figure()
self.fig.set_facecolor(bgcol)
# a FigureCanvas can be added as a QWidget, so we use that
self.plot = FigureCanvas(self.fig)
self.plot.setParent(parent)
self.ax = self.fig.add_subplot(111)
# TODO skip this, just do a redraw() after initialization?
self.ax.set_xlim(self.spurset.RFmin, self.spurset.RFmax)
self.ax.set_ylim(-0.5*self.spurset.dspan, 0.5*self.spurset.dspan)
self.ax.grid(True)
self.fig.tight_layout()
# a second figure to hold the legend
self.legendFig = Figure()
self.legendFig.set_facecolor(bgcol)
self.legendCanvas = FigureCanvas(self.legendFig)
self.legendFig.legend(*self.ax.get_legend_handles_labels(),
loc='upper left')
# connect up the picker watching
self.picked_obj = None
self._pick = self.plot.mpl_connect('pick_event', self.onpick)
self._drag = self.plot.mpl_connect('motion_notify_event', self.ondrag)
self._drop = self.plot.mpl_connect('button_release_event', self.ondrop)
示例6: __init__
def __init__(self):
"""Constructor"""
# Create the figure in the canvas
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
FigureCanvas.__init__(self, self.fig)
# generates first "empty" plot
t = [0.0]
e = [0.0]
self.line, = self.ax.plot(t,
e,
color="black",
linestyle="-",
linewidth=1.0)
# Set some options
self.T = {{L}} / {{U}}
self.Ek = {{E_KIN}}
self.ax.grid()
self.ax.set_xlim(0, 10.0)
self.ax.set_ylim(0.0, 1.1)
self.ax.set_autoscale_on(False)
self.ax.set_xlabel(r"$t U / L$", fontsize=21)
self.ax.set_ylabel(r"$\mathcal{E}_{k}(t) / \mathcal{E}_{k}(0)$", fontsize=21)
# force the figure redraw
self.fig.canvas.draw()
# call the update method (to speed-up visualization)
self.timerEvent(None)
# start timer, trigger event every 1000 millisecs (=1sec)
self.timer = self.startTimer(1000)
示例7: TrimCanvas
class TrimCanvas(QtGui.QWidget):
def __init__(self):
super(TrimCanvas, self).__init__()
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar2QT(self.canvas, self)
self.frames = None
self.data = None
self.handles = None
self.timedata = None
self.interval = None
def replot(self, mode):
data = plots.raw(f_sampling, self.data)
self.timedata = data['x_vector']
data['legend'] = 'Tymczasowe nagranie'
if mode == 'm':
data['sliders'] = (self.timedata[-1]*0.1, self.timedata[-1]*0.1 + self.interval, self.interval)
self.handles = plot_trimmable(self.figure, data)
else:
data['tight'] = True
self.handles = plot_function(self.figure, data)
self.canvas.draw()
def clear_data(self):
self.figure.clear()
self.canvas.draw()
self.frames = None
self.data = None
def data2frames(self):
bytes = self.data.tobytes()
self.frames = [bytes[i:i+2048] for i in range(0, len(bytes), 2048)]
示例8: histpanel
class histpanel(QtGui.QWidget):
def __init__(self,app):
super(histpanel,self).__init__()
self.layout =QtGui.QVBoxLayout()
self.setLayout(self.layout )
self.figure=plt.figure()
self.canvas=FigureCanvas(self.figure)
self.layout.addWidget(self.canvas)
self.histdata=[]
self.app=app
def plot(self,datastr):
data=json.loads(unicode(datastr))
if "history" in data["data"]:
self.histdata=np.array(data["data"]["history"])
self.timestep(datastr)
def timestep(self,resultstr):
data=json.loads(unicode(resultstr))
timestamp=data["data"]["stat"]["time"]
if ( self.app.tab.currentIndex()==2 ):
self.figure.clf()
ax=self.figure.add_subplot(111)
self.figure.set_frameon(False)
ax.patch.set_alpha(0)
ax.set_xlabel("Time [s]")
ax.set_ylabel("Image Count")
ppl.hist(ax,self.histdata-np.ceil(timestamp),bins=100,range=(-100,0))
ax.set_xlim((-100,0))
tstr= datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
ax.set_title(tstr +", "+ str(data["data"]["stat"]['images processed'])+" Images Processed")
self.canvas.draw()
示例9: __init__
def __init__(self, map_, width, height, parent=None, dpi=100, **matplot_args): # pylint: disable=W0613
# self._widthHint = width
# self._heightHint = height
self._origMap = map_
self._map = map_.resample((width, height))
# Old way (segfaults in some environements)
# self.figure = self._map.plot_simple(**matplot_args)
# FigureCanvas.__init__(self, self.figure)
self.figure = Figure()
self._map.plot(figure=self.figure, basic_plot=True, **matplot_args)
self.axes = self.figure.gca()
FigureCanvas.__init__(self, self.figure)
# How can we get the canvas to preserve its aspect ratio when expanding?
# sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
# sizePolicy.setHeightForWidth(True)
# self.setSizePolicy(sizePolicy)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
self.setSizePolicy(sizePolicy)
self.setMinimumSize(QtCore.QSize(width, height))
self.setMaximumSize(QtCore.QSize(width, height))
示例10: __init__
def __init__(self,parent=None,width=5,height=4,dpi=100):
figure = Figure(figsize=(width,height),dpi=dpi)
FigureCanvas.__init__(self,figure)
self.setParent(parent)
self.axes = figure.add_subplot(111)
self.axes.hold(False)
self.axeX = [0]
示例11: MainWidget
class MainWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(MainWidget, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays /embpyqt/python/the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QtGui.QPushButton('Plot')
self.button.clicked.connect(self.plot)
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
def plot(self):
''' plot some random stuff '''
# random data
'''data = [random.random() for i in range(2)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.hold(False)
# plot data
ax.plot(data, '*-')'''
m = Basemap(projection='robin',lon_0=0,resolution='c')#,latlon=True)
m.bluemarble(scale=0.2)
for friend in rpc.bridge.getFriendList():
print ''
pd = rpc.bridge.getPeerDetails(friend)
print pd['name']
print pd['extAddr']
ld = gi.record_by_addr(pd['extAddr'])
print ld
if ld:
print ld['latitude'],ld['longitude']
x, y = m(ld['longitude'],ld['latitude'])
#m.scatter(x, y,30,marker='o',color='k')
plt.plot(x, y,'ro')
plt.text(x,y,pd['name'],fontsize=9,
ha='center',va='top',color='r',
bbox = dict(boxstyle="square",ec='None',fc=(1,1,1,0.5)))
#plt.text(x,y,pd['name'],fontsize=14,fontweight='bold',
# ha='center',va='center',color='r')
# refresh canvas
self.canvas.draw()
示例12: Window
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.plot()
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.canvas)
self.setLayout(layout)
def plot(self):
''' plot some random stuff '''
# random data
data = [random.random() for i in range(10)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.hold(False)
# plot data
ax.plot(data, '*-')
# refresh canvas
self.canvas.draw()
示例13: __init__
def __init__(self, parent):
self.parent = parent
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
FigureCanvas.__init__(self, self.fig)
#self.cidPress = self.mpl_connect('button_press_event', self.onClick)
#self.cidRelease = self.mpl_connect('button_release_event', self.onRelease)
#self.X = np.random.rand(5,5)
#rows,cols,self.slices = self.X.shape
#self.Y = np.random.rand(5,5)
#rows,cols,self.slices = self.X.shape
newdata = np.ones(2*2)
newarray = np.reshape(newdata, (2, 2))
self.data = newarray
#self.im = self.ax.matshow(self.X[:,:])
#self.im = self.ax.matshow(self.data)
self.update()
self.fig.canvas.draw()
self.cnt = 0
self.setupSelector()
示例14: PlotWidget
class PlotWidget(QWidget):
"""
matplotlib plot widget
"""
def __init__(self,parent):
super(PlotWidget,self).__init__(parent)
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.ax = self.figure.add_subplot(111) # create an axis
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
def clear(self):
self.ax.cla()
def test(self):
""" plot random data """
df = fakeData()
#self.ax.hold(False) # discard old data
#self.ax.plot(df,'o-')
self.clear()
df.plot(ax=self.ax)
self.canvas.draw()
示例15: __init__
def __init__(self, parent=None,
size = (7,3.5),
dpi = 100,
logx = False,
logy = False,
legends = True,
bw = False):
self.fig = Figure(figsize=size, dpi=dpi) #in inches
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self,
qt.QSizePolicy.Expanding,
qt.QSizePolicy.Expanding)
self.curveTable = None
self.dpi=dpi
ddict = {'logx':logx,
'logy': logy,
'legends':legends,
'bw':bw}
self.ax=None
self.curveList = []
self.curveDict = {}
self.setParameters(ddict)
#self.setBlackAndWhiteEnabled(bw)
#self.setLogXEnabled(logx)
#self.setLogYEnabled(logy)
#self.setLegendsEnabled(legends)
self.xmin = None
self.xmax = None
self.ymin = None
self.ymax = None
self.limitsSet = False