本文整理汇总了Python中cbook.Stack类的典型用法代码示例。如果您正苦于以下问题:Python Stack类的具体用法?Python Stack怎么用?Python Stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stack类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
def add(self, key, a):
"""
Add Axes *a*, with key *key*, to the stack, and return the stack.
If *a* is already on the stack, don't add it again, but
return *None*.
"""
# All the error checking may be unnecessary; but this method
# is called so seldom that the overhead is negligible.
if not isinstance(a, Axes):
raise ValueError("second argument, %s, is not an Axes" % a)
try:
hash(key)
except TypeError:
raise ValueError("first argument, %s, is not a valid key" % key)
a_existing = self.get(key)
if a_existing is not None:
Stack.remove(self, (key, a_existing))
warnings.Warn(
"key %s already existed; Axes is being replaced" % key)
# I don't think the above should ever happen.
if a in self:
return None
self._ind += 1
return Stack.push(self, (key, (self._ind, a)))
示例2: __init__
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 is a w,h tuple in inches
dpi is dots per inch
subplotpars is a SubplotParams instance, defaults to rc
"""
Artist.__init__(self)
#self.set_figure(self)
self._axstack = Stack() # maintain the current axes
self._axobservers = []
self._seen = {} # axes args we've seen
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._unit_conversions = {}
self.dpi = Value(dpi)
self.figwidth = Value(figsize[0])
self.figheight = Value(figsize[1])
self.ll = Point( Value(0), Value(0) )
self.ur = Point( self.figwidth*self.dpi,
self.figheight*self.dpi )
self.bbox = Bbox(self.ll, self.ur)
self.frameon = frameon
self.transFigure = get_bbox_transform( unit_bbox(), self.bbox)
self.figurePatch = Rectangle(
xy=(0,0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor,
linewidth=linewidth,
)
self._set_artist_props(self.figurePatch)
self._hold = rcParams['axes.hold']
self.canvas = None
if subplotpars is None:
subplotpars = SubplotParams()
self.subplotpars = subplotpars
self.clf()
self._cachedRenderer = None
示例3: remove
def remove(self, a):
Stack.remove(self, self._entry_from_axes(a))
示例4: Figure
class Figure(Artist):
def __str__(self):
return "Figure(%gx%g)"%(self.figwidth.get(),self.figheight.get())
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 is a w,h tuple in inches
dpi is dots per inch
subplotpars is a SubplotParams instance, defaults to rc
"""
Artist.__init__(self)
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 = Value(dpi)
self.figwidth = Value(figsize[0])
self.figheight = Value(figsize[1])
self.ll = Point( Value(0), Value(0) )
self.ur = Point( self.figwidth*self.dpi,
self.figheight*self.dpi )
self.bbox = Bbox(self.ll, self.ur)
self.frameon = frameon
self.transFigure = get_bbox_transform( unit_bbox(), self.bbox)
self.figurePatch = Rectangle(
xy=(0,0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor,
linewidth=linewidth,
)
self._set_artist_props(self.figurePatch)
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 autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
"""
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. This function will raise a
RuntimeError if any of the Axes are not Subplots.
bottom : the bottom of the subplots for subplots_adjust
rotation: the rotation of the xtick labels
ha : the horizontal alignment of the xticklabels
"""
for ax in self.get_axes():
if not hasattr(ax, 'is_last_row'):
raise RuntimeError('Axes must be subplot instances; found %s'%type(ax))
if ax.is_last_row():
for label in ax.get_xticklabels():
label.set_ha(ha)
label.set_rotation(rotation)
else:
for label in ax.get_xticklabels():
label.set_visible(False)
self.subplots_adjust(bottom=bottom)
def get_children(self):
'get a list of artists contained in the figure'
children = [self.figurePatch]
children.extend(self.axes)
children.extend(self.lines)
children.extend(self.patches)
children.extend(self.texts)
children.extend(self.images)
children.extend(self.legends)
return children
def contains(self, mouseevent):
#.........这里部分代码省略.........
示例5: Figure
class Figure(Artist):
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 is a w,h tuple in inches
dpi is dots per inch
subplotpars is a SubplotParams instance, defaults to rc
"""
Artist.__init__(self)
#self.set_figure(self)
self._axstack = Stack() # maintain the current axes
self._axobservers = []
self._seen = {} # axes args we've seen
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._unit_conversions = {}
self.dpi = Value(dpi)
self.figwidth = Value(figsize[0])
self.figheight = Value(figsize[1])
self.ll = Point( Value(0), Value(0) )
self.ur = Point( self.figwidth*self.dpi,
self.figheight*self.dpi )
self.bbox = Bbox(self.ll, self.ur)
self.frameon = frameon
self.transFigure = get_bbox_transform( unit_bbox(), self.bbox)
self.figurePatch = Rectangle(
xy=(0,0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor,
linewidth=linewidth,
)
self._set_artist_props(self.figurePatch)
self._hold = rcParams['axes.hold']
self.canvas = None
if subplotpars is None:
subplotpars = SubplotParams()
self.subplotpars = subplotpars
self.clf()
self._cachedRenderer = None
def get_window_extent(self, *args, **kwargs):
'get the figure bounding box in display space'
return self.bbox
def set_canvas(self, canvas):
"""
Set the canvas the contains the figure
ACCEPTS: a FigureCanvas instance
"""
self.canvas = canvas
def _get_unit_conversion(self, python_type):
"""
Get a unit conversion corresponding to a python type
"""
maps = [self._unit_conversions, Figure._default_unit_conversions]
for m in maps:
classes = [python_type]
for current in classes:
if (current in m):
# found it!
#print 'Found unit conversion for %s!' % (`python_type`)
return m[current]
return None
def register_unit_conversion(self, python_type, conversion):
"""
Register a unit conversion class
ACCEPTS: a Unit instance
"""
self._unit_conversions[python_type] = conversion
def unregister_unit_conversion(self, python_type):
"""
Unregister a unit conversion class
#.........这里部分代码省略.........
示例6: bubble
def bubble(self, a):
"""
Move the given axes, which must already exist in the
stack, to the top.
"""
return Stack.bubble(self, self._entry_from_axes(a))
示例7: remove
def remove(self, a):
"""Remove the axes from the stack."""
Stack.remove(self, self._entry_from_axes(a))
示例8: bubble
def bubble(self, a):
return Stack.bubble(self, self._entry_from_axes(a))