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):
#.........这里部分代码省略.........
请发表评论