本文整理汇总了Python中matplotlib.backends.backend_wxagg.FigureCanvasWxAgg.get_renderer方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasWxAgg.get_renderer方法的具体用法?Python FigureCanvasWxAgg.get_renderer怎么用?Python FigureCanvasWxAgg.get_renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_wxagg.FigureCanvasWxAgg
的用法示例。
在下文中一共展示了FigureCanvasWxAgg.get_renderer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlotPanel
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import get_renderer [as 别名]
#.........这里部分代码省略.........
self.autoset_margins()
self.SetSizer(sizer)
self.Fit()
canvas_draw = self.canvas.draw
def draw(*args, **kws):
self.autoset_margins()
canvas_draw(*args, **kws)
self.canvas.draw = draw
self.addCanvasEvents()
def _updateCanvasDraw(self):
""" Overload of the draw function that update
axes position before each draw"""
fn = self.canvas.draw
def draw2(*a,**k):
self._updateGridSpec()
return fn(*a,**k)
self.canvas.draw = draw2
def get_default_margins(self):
"""get default margins"""
trans = self.fig.transFigure.inverted().transform
# Static margins
l, t, r, b = self.axesmargins
(l, b), (r, t) = trans(((l, b), (r, t)))
# Extent
dl, dt, dr, db = 0, 0, 0, 0
for i, ax in enumerate(self.fig.get_axes()):
(x0, y0),(x1, y1) = ax.get_position().get_points()
try:
(ox0, oy0), (ox1, oy1) = ax.get_tightbbox(self.canvas.get_renderer()).get_points()
(ox0, oy0), (ox1, oy1) = trans(((ox0 ,oy0),(ox1 ,oy1)))
dl = min(0.2, max(dl, (x0 - ox0)))
dt = min(0.2, max(dt, (oy1 - y1)))
dr = min(0.2, max(dr, (ox1 - x1)))
db = min(0.2, max(db, (y0 - oy0)))
except:
pass
return (l + dl, t + dt, r + dr, b + db)
def autoset_margins(self):
"""auto-set margins left, bottom, right, top
according to the specified margins (in pixels)
and axes extent (taking into account labels,
title, axis)
"""
if not self.conf.auto_margins:
return
# coordinates in px -> [0,1] in figure coordinates
trans = self.fig.transFigure.inverted().transform
# Static margins
if not self.use_dates:
self.conf.margins = l, t, r, b = self.get_default_margins()
self.gridspec.update(left=l, top=1-t, right=1-r, bottom=b)
# Axes positions update
for ax in self.fig.get_axes():
try:
ax.update_params()
except ValueError:
pass
ax.set_position(ax.figbox)
示例2: WXSlidingPlot
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import get_renderer [as 别名]
#.........这里部分代码省略.........
#print i,self.cached_datax[i]
# If some points are beyond the window, move the window
if len(self.cached_datax[i]) > 0 and self.cached_datax[i][-1] > self.begin + self.span:
#print 42, self.cached_datax[i][-1]
self.begin = self.cached_datax[i][-1] - self.span
# No need for replot, we have to reallocate
if self._doRePlot:
return
# Remove the points behind the window
for i in range(len(self.lines)):
# Bad points to move?
if len(self.cached_datax[i]) > 0 and self.cached_datax[i][0] < self.begin:
index = 0
# Could be faster by divide and conquer...
while index < len(self.cached_datax[i]) and self.cached_datax[i][index] < self.begin :
index += 1
# Prune out old data
self.cached_datax[i] = self.cached_datax[i][index:]
self.cached_datay[i] = self.cached_datay[i][index:]
# Set line data.
self.lines[i].set_data(numpy.array(self.cached_datax[i])-self.begin, \
numpy.array(self.cached_datay[i]))
self.canvas.restore_region(self.background)
for line in self.lines:
self.ax.draw_artist(line)
self.canvas.blit(None)
#self.canvas.blit(changes_box_inframe)
#except :
#pass
#print '>>>>>>>>>>>>>>'
#print e
def _createContent(self):
print 'create content'
self.cached_datax = []
self.cached_datay = []
print self.channels
for c in self.channels:
self.cached_datax.append([])
self.cached_datay.append([])
c.flush()
self._doFlush = False
def _resizeCreateContent(self):
"""Resize graph according to user input and initialize plots"""
self.lines=[]
for c in self.channels:
data=c.getNext()
line, = self.ax.plot(data[0],data[1], c.style, animated = True)
self.lines.append(line)
gca = self.fig.gca()
#TODO: add an auto mode here
if self.ylim:
gca.set_ylim(self.ylim)
else:
if self.autolim:
diff = self.autolim[1] - self.autolim[0]
gca.set_ylim([self.autolim[0] - 0.1*diff, self.autolim[1] + 0.1*diff])
else:
gca.set_ylim([-1,1])
#gca.set_xlim([self.begin, (self.begin+self.span)])
gca.set_xlim([0, (self.span)])
self.ax.grid()
self.canvas.draw()
self.background = None
self._doRePlot = False
print 'R'
def _createGraphics(self):
"""Reallocate new figure and take care of panel resizing issues"""
self.fig=Figure()
self.canvas=FigureCanvas(self,-1,self.fig)
self.ax = self.fig.add_subplot(111)
self.ax._cachedRenderer=self.canvas.get_renderer()
def _onSize(self, evt):
self._resizeFlag = True
def _onIdle(self, event):
event.RequestMore(True)
if self._resizeFlag:
self._resizeFlag = False
self._SetSize()
self.draw_plot()
def _SetSize(self, pixels=None):
if not pixels:
pixels = self.GetClientSize()
self._createGraphics()
self.canvas.SetSize(pixels)
self.fig.set_size_inches(pixels[0]/self.fig.get_dpi(),
pixels[1]/self.fig.get_dpi(), forward=True)
self._doRePlot = True
示例3: MyPlot
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import get_renderer [as 别名]
class MyPlot(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self,parent, -1)
self.fig = None
self.canvas = None
self.ax = None
self.background = None
self.lines = []
self._doRePlot = True
self.foo = 1
self.t = time.time()
self.blit_time=0
self.y = numpy.cos(numpy.arange(0.0,1.0,0.1))
self.ylim = None
self.autolim = None
self.span = 500
self.begin = 0
self.channels = []
self._SetSize()
self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
self._resizeFlag = True
sizer=wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas,1,wx.GROW)
self.SetSizer(sizer)
self.canvas.Show()
def addChannel(self, channel):
self.channels.append(channel)
def setTimespan(self, span):
self.span = span
def setYlim(self, ymin, ymax):
self.ylim = [ymin, ymax]
def _resizeCreateContent(self):
'''Resize graph according to user input and initialize plots'''
self.lines=[]
for c in self.channels:
data=c.getNext()
line, = self.ax.plot(data[0],data[1], animated = True)
self.lines.append(line)
gca = self.fig.gca()
#TODO: add an auto mode here
if self.ylim:
gca.set_ylim(self.ylim)
else:
if self.autolim:
diff = self.autolim[1] - self.autolim[0]
gca.set_ylim([self.autolim[0] - 0.1*diff, self.autolim[1] + 0.1*diff])
else:
gca.set_ylim([-1,1])
gca.set_xlim([self.begin, (self.begin+self.span)])
self.ax.grid()
#self.fig.clear()
self.canvas.draw()
self.background = None
print 'content'
self._doRePlot = False
def _createGraphics(self):
"""Reallocate new figure and take care of panel resizing issues"""
self.fig=Figure()
self.canvas=FigureCanvas(self,-1,self.fig)
self.ax = self.fig.add_subplot(111)
self.ax._cachedRenderer=self.canvas.get_renderer()
def _onSize(self, evt):
self._resizeFlag = True
def _onIdle(self, event):
event.RequestMore(True)
if self._resizeFlag:
self._resizeFlag = False
self._SetSize()
self.draw_plot()
#if self.foo > 2000:
#u=time.time()
#print self.foo/(u-self.t), self.blit_time/(u-self.t)
#exit(0)
def _SetSize(self, pixels=None):
if not pixels:
pixels = self.GetClientSize()
self._createGraphics()
self.canvas.SetSize(pixels)
self.fig.set_size_inches(pixels[0]/self.fig.get_dpi(),
#.........这里部分代码省略.........
示例4: WXPlot
# 需要导入模块: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg [as 别名]
# 或者: from matplotlib.backends.backend_wxagg.FigureCanvasWxAgg import get_renderer [as 别名]
#.........这里部分代码省略.........
else:
self.autolim = [ min(data[1]), min(data[1]) ]
if changes_box is None:
changes_box = Bbox.unit()
changes_box.update_from_data(numpy.array(data[0]), \
numpy.array(data[1]), ignore=changes_box.is_unit())
if not self._doRePlot and len(data[0]) > 0 :
end = data[0][-1]
if end > self.begin+self.span:
self.begin = end
self._doRePlot = True
#print 'C'
#self.cached_datax[i] += (data[0])
#self.cached_datay[i] += (data[1])
#print self.cached_datay[i], self.cached_datax[i]
self.lines[i].set_data(self.cached_datax[i], \
self.cached_datay[i])
#self.lines[i].set_data(data[0], data[1])
else:
self.lines[i].set_data([], [])
if not changes_box:
return
for line in self.lines:
self.ax.draw_artist(line)
tr = line.get_transform()
changes_box_inframe = changes_box.transformed(tr)
box_xpadding = 20
box_ypadding = 100
(x,y,l,w) = changes_box_inframe.bounds
changes_box_inframe = Bbox.from_bounds(x-box_xpadding, \
y-box_ypadding, l+2*box_xpadding, w+2*box_ypadding)
#self.canvas.blit(None)
self.canvas.blit(changes_box_inframe)
#except :
#pass
#print '>>>>>>>>>>>>>>'
#print e
def _resizeCreateContent(self):
"""Resize graph according to user input and initialize plots"""
self.lines=[]
for c in self.channels:
data=c.getNext()
line, = self.ax.plot(data[0],data[1], c.style, animated = True)
self.lines.append(line)
self.cached_datax.append([])
self.cached_datay.append([])
gca = self.fig.gca()
#TODO: add an auto mode here
if self.ylim:
gca.set_ylim(self.ylim)
else:
if self.autolim:
diff = self.autolim[1] - self.autolim[0]
gca.set_ylim([self.autolim[0] - 0.1*diff, self.autolim[1] + 0.1*diff])
else:
gca.set_ylim([-1,1])
gca.set_xlim([self.begin, (self.begin+self.span)])
self.ax.grid()
self.canvas.draw()
self.background = None
self._doRePlot = False
def _createGraphics(self):
"""Reallocate new figure and take care of panel resizing issues"""
self.fig=Figure()
self.canvas=FigureCanvas(self,-1,self.fig)
self.ax = self.fig.add_subplot(111)
self.ax._cachedRenderer=self.canvas.get_renderer()
def _onSize(self, evt):
self._resizeFlag = True
def _onIdle(self, event):
event.RequestMore(True)
if self._resizeFlag:
self._resizeFlag = False
self._SetSize()
self.draw_plot()
def _SetSize(self, pixels=None):
if not pixels:
pixels = self.GetClientSize()
self._createGraphics()
self.canvas.SetSize(pixels)
self.fig.set_size_inches(pixels[0]/self.fig.get_dpi(),
pixels[1]/self.fig.get_dpi(), forward=True)
self._doRePlot = True