本文整理汇总了Python中cbook.Stack.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.clear方法的具体用法?Python Stack.clear怎么用?Python Stack.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cbook.Stack
的用法示例。
在下文中一共展示了Stack.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cbook import Stack [as 别名]
# 或者: from cbook.Stack import clear [as 别名]
#.........这里部分代码省略.........
self._xypress = None
self._button_pressed == None
self.push_current()
self.release(event)
def fix_aspect_after_zoom(self,a):
'Fix the aspect ratio after zooming in case of aspect equal or scaled'
lold,bold,wold,hold = a.get_position()
aspect = a.get_aspect()
a.set_aspect(aspect,True)
l,b,w,h = a.get_position()
if w != wold: # width of axes was changed
ratio = w / wold
for ax in a.get_figure().axes: # see if any subplot shares this axis
if ax._sharex == a:
lax,bax,wax,hax = ax.get_position()
wnew = ratio * wax
lnew = lax
if aspect == 'equal': lnew = lax - 0.5 * ( wnew - wax )
ax.set_position( [lnew, bax, wnew, hax] )
def draw(self):
'redraw the canvases, update the locators'
for a in self.canvas.figure.get_axes():
xaxis = getattr(a, 'xaxis', None)
yaxis = getattr(a, 'yaxis', None)
locators = []
if xaxis is not None:
locators.append(xaxis.get_major_locator())
locators.append(xaxis.get_minor_locator())
if yaxis is not None:
locators.append(yaxis.get_major_locator())
locators.append(yaxis.get_minor_locator())
for loc in locators:
loc.refresh()
self.canvas.draw()
def _update_view(self):
'update the viewlim and position from the view and position stack for each axes'
lims = self._views()
if lims is None: return
pos = self._positions()
if pos is None: return
for i, a in enumerate(self.canvas.figure.get_axes()):
xmin, xmax, ymin, ymax = lims[i]
a.set_xlim((xmin, xmax))
a.set_ylim((ymin, ymax))
a.set_position( pos[i] )
self.draw()
def save_figure(self, *args):
'save the current figure'
raise NotImplementedError
def set_cursor(self, cursor):
"""
Set the current cursor to one of the backend_bases.Cursors
enums values
"""
pass
def update(self):
'reset the axes stack'
self._views.clear()
self._positions.clear()
self.set_history_buttons()
def zoom(self, *args):
'activate zoom to rect mode'
if self._active == 'ZOOM':
self._active = None
else:
self._active = 'ZOOM'
if self._idPress is not None:
self._idPress=self.canvas.mpl_disconnect(self._idPress)
self.mode = ''
if self._idRelease is not None:
self._idRelease=self.canvas.mpl_disconnect(self._idRelease)
self.mode = ''
if self._active:
self._idPress = self.canvas.mpl_connect('button_press_event', self.press_zoom)
self._idRelease = self.canvas.mpl_connect('button_release_event', self.release_zoom)
self.mode = 'Zoom to rect mode'
self.set_message(self.mode)
def set_history_buttons(self):
'enable or disable back/forward button'
pass
示例2: Figure
# 需要导入模块: from cbook import Stack [as 别名]
# 或者: from cbook.Stack import clear [as 别名]
class Figure(Artist):
"""
The Figure instance supports callbacks through a *callbacks*
attribute which is a :class:`matplotlib.cbook.CallbackRegistry`
instance. The events you can connect to are 'dpi_changed', and
the callback will be called with ``func(fig)`` where fig is the
:class:`Figure` instance.
The figure patch is drawn by a the attribute
*patch*
a :class:`matplotlib.patches.Rectangle` instance
*suppressComposite*
for multiple figure images, the figure will make composite
images depending on the renderer option_image_nocomposite
function. If suppressComposite is True|False, this will
override the renderer
"""
def __str__(self):
return "Figure(%gx%g)" % tuple(self.bbox.size)
def __init__(
self,
figsize=None, # defaults to rc figure.figsize
dpi=None, # defaults to rc figure.dpi
facecolor=None, # defaults to rc figure.facecolor
edgecolor=None, # defaults to rc figure.edgecolor
linewidth=1.0, # the default linewidth of the frame
frameon=True, # whether or not to draw the figure frame
subplotpars=None, # default to rc
):
"""
*figsize*
w,h tuple in inches
*dpi*
dots per inch
*facecolor*
the figure patch facecolor; defaults to rc ``figure.facecolor``
*edgecolor*
the figure patch edge color; defaults to rc ``figure.edgecolor``
*linewidth*
the figure patch edge linewidth; the default linewidth of the frame
*frameon*
if False, suppress drawing the figure frame
*subplotpars*
a :class:`SubplotParams` instance, defaults to rc
"""
Artist.__init__(self)
self.callbacks = cbook.CallbackRegistry(('dpi_changed', ))
if figsize is None: figsize = rcParams['figure.figsize']
if dpi is None: dpi = rcParams['figure.dpi']
if facecolor is None: facecolor = rcParams['figure.facecolor']
if edgecolor is None: edgecolor = rcParams['figure.edgecolor']
self.dpi_scale_trans = Affine2D()
self.dpi = dpi
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
self.frameon = frameon
self.transFigure = BboxTransformTo(self.bbox)
self.patch = self.figurePatch = Rectangle(
xy=(0, 0),
width=1,
height=1,
facecolor=facecolor,
edgecolor=edgecolor,
linewidth=linewidth,
)
self._set_artist_props(self.patch)
self._hold = rcParams['axes.hold']
self.canvas = None
if subplotpars is None:
subplotpars = SubplotParams()
self.subplotpars = subplotpars
self._axstack = Stack() # maintain the current axes
self.axes = []
self.clf()
self._cachedRenderer = None
def _get_dpi(self):
return self._dpi
def _set_dpi(self, dpi):
self._dpi = dpi
self.dpi_scale_trans.clear().scale(dpi, dpi)
self.callbacks.process('dpi_changed', self)
dpi = property(_get_dpi, _set_dpi)
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
"""
Date ticklabels often overlap, so it is useful to rotate them
and right align them. Also, a common use case is a number of
subplots with shared xaxes where the x-axis is date data. The
ticklabels are often long, and it helps to rotate them on the
bottom subplot and turn them off on other subplots, as well as
turn off xlabels.
*bottom*
the bottom of the subplots for :meth:`subplots_adjust`
*rotation*
the rotation of the xtick labels
*ha*
#.........这里部分代码省略.........
示例3: Figure
# 需要导入模块: from cbook import Stack [as 别名]
# 或者: from cbook.Stack import clear [as 别名]
#.........这里部分代码省略.........
if not len(args): return
if isinstance(args[0], Subplot) or isinstance(args[0], PolarSubplot):
a = args[0]
assert(a.get_figure() is self)
else:
ispolar = kwargs.pop('polar', False)
if ispolar:
a = PolarSubplot(self, *args, **kwargs)
else:
a = Subplot(self, *args, **kwargs)
self.axes.append(a)
self._axstack.push(a)
self.sca(a)
self._seen[key] = a
return a
add_subplot.__doc__ = dedent(add_subplot.__doc__) % artist.kwdocd
def clf(self):
"""
Clear the figure
"""
for ax in tuple(self.axes): # Iterate over the copy.
ax.cla()
self.delaxes(ax) # removes ax from self.axes
toolbar = getattr(self.canvas, 'toolbar', None)
if toolbar is not None:
toolbar.update()
self._axstack.clear()
self._seen = {}
self.lines = []
self.patches = []
self.texts=[]
self.images = []
self.legends = []
self._axobservers = []
def clear(self):
"""
Clear the figure
"""
self.clf()
def draw(self, renderer):
"""
Render the figure using Renderer instance renderer
"""
# draw the figure bounding box, perhaps none for white figure
#print 'figure draw'
if not self.get_visible(): return
renderer.open_group('figure')
self.transFigure.freeze() # eval the lazy objects
if self.frameon: self.figurePatch.draw(renderer)
for p in self.patches: p.draw(renderer)
for l in self.lines: l.draw(renderer)
if len(self.images)<=1 or renderer.option_image_nocomposite() or not allequal([im.origin for im in self.images]):
for im in self.images:
im.draw(renderer)