本文整理汇总了Python中matplotlib.backends.backend_agg.FigureCanvasAgg.get_renderer方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasAgg.get_renderer方法的具体用法?Python FigureCanvasAgg.get_renderer怎么用?Python FigureCanvasAgg.get_renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_agg.FigureCanvasAgg
的用法示例。
在下文中一共展示了FigureCanvasAgg.get_renderer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __get_column_width
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def __get_column_width(self):
max_length = 0
max_column_text = ''
flag = self.prefs.get('legend_numbers',True)
unit = self.prefs.get('legend_unit',False)
for label,num in self.labels:
if not flag: num = None
if num is not None:
column_length = len(str(label)+str(num)) + 1
else:
column_length = len(str(label)) + 1
if column_length > max_length:
max_length = column_length
if flag:
if type(num) == types.IntType or type(num) == types.LongType:
numString = str(num)
else:
numString = "%.1f" % float(num)
max_column_text = '%s %s' % (str(label),numString)
if unit:
max_column_text += "%"
else:
max_column_text = '%s ' % str(label)
figure = Figure()
canvas = FigureCanvasAgg(figure)
dpi = self.prefs['dpi']
figure.set_dpi( dpi )
l_size,l_padding = self.__get_legend_text_size()
self.text_size = pixelToPoint(l_size,dpi)
text = Text(0.,0.,text=max_column_text,size=self.text_size)
text.set_figure(figure)
bbox = text.get_window_extent(canvas.get_renderer())
self.column_width = bbox.width+6*l_size
示例2: print_png
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def print_png(self, filename, *args, **kwargs):
'''Call the widget function to make a png of the widget.
'''
fig = FigureCanvasAgg(self.figure)
FigureCanvasAgg.draw(fig)
l, b, w, h = self.figure.bbox.bounds
texture = Texture.create(size=(w, h))
texture.blit_buffer(bytes(fig.get_renderer().buffer_rgba()),
colorfmt='rgba', bufferfmt='ubyte')
texture.flip_vertical()
img = Image(texture)
img.save(filename)
示例3: get_renderer
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def get_renderer(fig):
if fig._cachedRenderer:
renderer = fig._cachedRenderer
else:
canvas = fig.canvas
if canvas and hasattr(canvas, "get_renderer"):
renderer = canvas.get_renderer()
else:
# not sure if this can happen
warnings.warn("tight_layout : falling back to Agg renderer")
from matplotlib.backends.backend_agg import FigureCanvasAgg
canvas = FigureCanvasAgg(fig)
renderer = canvas.get_renderer()
return renderer
示例4: get_renderer
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def get_renderer(fig):
if fig._cachedRenderer:
renderer = fig._cachedRenderer
else:
canvas = fig.canvas
if canvas and hasattr(canvas, "get_renderer"):
renderer = canvas.get_renderer()
else:
# not sure if this can happen
# seems to with PDF...
_log.info("constrained_layout : falling back to Agg renderer")
from matplotlib.backends.backend_agg import FigureCanvasAgg
canvas = FigureCanvasAgg(fig)
renderer = canvas.get_renderer()
return renderer
示例5: draw_tree
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def draw_tree(canvas, figure, loc = (0,0)):
"""Draws the tree figure onto the tree canvas."""
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
# Position: convert from top-left anchor to center anchor
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
# Unfortunately, there's no accessor for the pointer to the native renderer
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
# Return a handle which contains a reference to the photo object
# which must be kept live or else the picture disappears
return photo
示例6: get_image
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def get_image(self):
width = self.extent[1] - self.extent[0]
height = self.extent[3] - self.extent[2]
self.figure.set_size_inches((6, 6. * width / height))
self.figure.set_dpi(self.settings.exportDpi)
self.figure.patch.set_alpha(0)
self.axes.axesPatch.set_alpha(0)
canvas = FigureCanvasAgg(self.figure)
canvas.draw()
renderer = canvas.get_renderer()
if matplotlib.__version__ >= '1.2':
buf = renderer.buffer_rgba()
else:
buf = renderer.buffer_rgba(0, 0)
size = canvas.get_width_height()
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
return image
示例7: export_image
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def export_image(filename, format, figure):
oldSize = figure.get_size_inches()
oldDpi = figure.get_dpi()
figure.set_size_inches((8, 4.5))
figure.set_dpi(600)
canvas = FigureCanvasAgg(figure)
canvas.draw()
renderer = canvas.get_renderer()
if matplotlib.__version__ >= '1.2':
buf = renderer.buffer_rgba()
else:
buf = renderer.buffer_rgba(0, 0)
size = canvas.get_width_height()
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
image = image.convert('RGB')
ext = File.get_export_ext(format, File.Exports.IMAGE)
image.save(filename, format=ext[1::])
figure.set_size_inches(oldSize)
figure.set_dpi(oldDpi)
示例8: draw_figure
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def draw_figure(canvas, figure, loc=(0, 0)):
""" Draw a matplotlib figure onto a Tk canvas
loc: location of top-left corner of figure on canvas in pixels.
Inspired by matplotlib source: lib/matplotlib/backends/backend_tkagg.py
"""
figure_canvas_agg = FigureCanvasAgg(figure)
figure_canvas_agg.draw()
figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds
figure_w, figure_h = int(figure_w), int(figure_h)
photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h)
# Position: convert from top-left anchor to center anchor
canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo)
# Unfortunately, there's no accessor for the pointer to the native renderer
tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
# Return a handle which contains a reference to the photo object
# which must be kept live or else the picture disappears
return photo
示例9: __draw_image
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def __draw_image(self, sizeInches, ppi):
oldSize = self.figure.get_size_inches()
oldDpi = self.figure.get_dpi()
self.figure.set_size_inches(sizeInches)
self.figure.set_dpi(ppi)
canvas = FigureCanvasAgg(self.figure)
canvas.draw()
renderer = canvas.get_renderer()
if matplotlib.__version__ >= '1.2':
buf = renderer.buffer_rgba()
else:
buf = renderer.buffer_rgba(0, 0)
size = canvas.get_width_height()
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
self.figure.set_size_inches(oldSize)
self.figure.set_dpi(oldDpi)
imageWx = wx.EmptyImage(image.size[0], image.size[1])
imageWx.SetData(image.convert('RGB').tostring())
return imageWx
示例10: __plot
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def __plot(self, mousePos=None):
figure, axes = plt.subplots()
dpi = figure.get_dpi()
viewSize = self._graphicsView.size()
scrollSize = self._graphicsView.style().pixelMetric(QtGui.QStyle.PM_ScrollBarExtent)
size = QtCore.QSize(viewSize.width() * self._scale - scrollSize,
viewSize.height() * self._scale - scrollSize)
figure.set_size_inches(size.width() / float(dpi),
size.height() / float(dpi))
figure.patch.set_facecolor('w')
plt.title('Signals')
plt.xlabel('Frequency (MHz)')
plt.ylabel('Detections')
plt.grid(True)
if matplotlib.__version__ >= '1.2':
figure.tight_layout()
renderer = plt.gcf().canvas.get_renderer()
formatter = ScalarFormatter(useOffset=False)
axes.xaxis.set_major_formatter(formatter)
axes.yaxis.set_major_formatter(formatter)
if self._show_all:
signals = self._signals
else:
signals = [signal for signal in self._signals
if signal[0] not in self._filtered]
x, z, y, _levels = zip(*signals)
x = [freq / 1e6 for freq in x]
if len(x) > 2:
width = min(numpy.diff(x)) / 2.
else:
width = 20 / 1e6
bars = axes.bar(x, y, width=width, color='blue')
xmin, xmax = plt.xlim()
ymin, ymax = plt.ylim()
for i in range(len(y)):
bar = bars[i]
freq = x[i]
rate = z[i]
height = bar.get_height()
text = axes.text(bar.get_x() + width / 2.,
height,
'{:.4f} ({:.1f})'.format(freq, rate),
rotation=45,
ha='left', va='bottom', size='smaller')
if matplotlib.__version__ >= '1.3':
effect = patheffects.withStroke(linewidth=2,
foreground="w",
alpha=0.75)
text.set_path_effects([effect])
bounds = text.get_window_extent(renderer)
bounds = bounds.transformed(axes.transData.inverted())
extents = bounds.extents
xmin = min(xmin, extents[0])
ymin = min(ymin, extents[1])
xmax = max(xmax, extents[2])
ymax = max(ymax, extents[3])
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
canvas = FigureCanvasAgg(figure)
canvas.draw()
renderer = canvas.get_renderer()
if matplotlib.__version__ >= '1.2':
rgba = renderer.buffer_rgba()
else:
rgba = renderer.buffer_rgba(0, 0)
image = QtGui.QImage(rgba, size.width(), size.height(),
QtGui.QImage.Format_ARGB32)
pixmap = QtGui.QPixmap.fromImage(image)
scene = QtGui.QGraphicsScene(self)
scene.addPixmap(pixmap)
scene.setSceneRect(image.rect())
self._graphicsView.setScene(scene)
if mousePos is not None:
self._graphicsView.centerOn(mousePos.x() * self._scale,
mousePos.y() * self._scale)
plt.close()
示例11: make_png
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def make_png(md5hash, cmap='gray', sigma=1.0, crop=False, options='', annotation=''):
"""Create a PNG stamp from a FITS file.
:param md5hash:
:param cmap:
:param sigma:
:param crop:
:param options:
:param annotation:
:return:
"""
outFile = md5hash
# Read
fitsim = maputils.FITSimage(outFile+'.fit')
fig = Figure(figsize=(5,5), facecolor="#ffffff")
canvas = FigureCanvas(fig)
frame = fig.add_subplot(1,1,1)
# Work out scaling
dat = fitsim.dat.ravel()
dat = dat.compress(dat>0.0)
if len(dat)>10:
z1, z2 = astats.zscale(dat, nsample=min(1000,len(dat)))
else:
z1 = z2 = 0.0
# Options
cmapinverse=False
if ('H' in options):
cmap='hot'
if ('W' in options):
cmap='winter'
if ('I' in options):
cmap=cmap+'_r'
annim = fitsim.Annotatedimage(frame, cmap=cmap.replace('_r',''), clipmin=z1, clipmax=z2*sigma)
if cmap.find('_r')>0:
annim.cmap.set_inverse(True)
annim.Image()
# Work out grid
a,d = fitsim.convproj.toworld(((0,0),(0,fitsim.hdr['NAXIS2'])))
b = numpy.array([5,10,15,20,25,30,35,40,45,50,55,60])
j = b.searchsorted(int(math.sqrt((a[0]-a[1])**2+(d[0]-d[1])**2)*3600.)/6)
deltay = b[j]
grat = annim.Graticule(
starty=fitsim.hdr['CRVAL2'], deltay=deltay/3600.,
startx=fitsim.hdr['CRVAL1'], deltax=deltay/3600./math.cos(math.radians(d[0])))
grat.setp_lineswcs0(visible=False)
grat.setp_lineswcs1(visible=False)
grat.setp_plotaxis(0, mode=0, label='')
grat.setp_plotaxis(1, mode=0, label='')
grat.setp_plotaxis(2, mode=0, label='')
grat.setp_plotaxis(3, mode=0, label='')
grat.setp_tick(visible=False)
grat.setp_tickmark(color='#99FF99', markersize=4, markeredgewidth=2)
# Plot center cross
xcen, ycen = fitsim.hdr['NAXIS1']/2.+0.5,fitsim.hdr['NAXIS2']/2.+0.5
frame.plot([xcen,xcen],[ycen/6.,ycen-ycen/6.],linewidth=1,color='#99FF99')
frame.plot([xcen,xcen],[ycen+ycen/6.,ycen*2-ycen/6.],linewidth=1,color='#99FF99')
frame.plot([xcen/6.,xcen-xcen/6.],[ycen,ycen],linewidth=1,color='#99FF99')
frame.plot([xcen+ycen/6.,xcen*2-ycen/6.],[ycen,ycen],linewidth=1,color='#99FF99')
annim.plot()
if (annotation):
frame.fill([0.001,0.999,0.999,0.001], [0.999,0.999,0.90-0.08, 0.90-0.08], transform = frame.transAxes, edgecolor='none', facecolor='#000000', alpha=0.4)
i = 0
for item in annotation.split('\\n'):
frame.text(0.04,0.92-i*0.06, item, transform = frame.transAxes, color='#FFFFFF')
i = i + 1
canvas.draw()
if crop:
size = canvas.get_renderer().get_canvas_width_height()
buf = canvas.tostring_rgb()
im = PILImage.fromstring('RGB', map(int, size), buf, 'raw', 'RGB', 0, 1)
im2 = im.convert('L'); im2 = PILImageOps.invert(im2)
im=im.crop(im2.getbbox())
im.save(outFile+'.png', 'PNG')
else:
s = StringIO.StringIO()
canvas.print_png(s)
s.flush()
s.seek(0)
open(outFile+'.png','w').write(s.read())
time.sleep(0.25)
示例12: if
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
while disp.isNotDone():
ax = fig.gca(projection='3d')
ax.set_xlabel('BLUE', color=(0,0,1) )
ax.set_ylabel('GREEN',color=(0,1,0))
ax.set_zlabel('RED',color=(1,0,0))
# Get the color histogram
img = cam.getImage().scale(0.3)
rgb = img.getNumpyCv2()
hist = cv2.calcHist([rgb],[0,1,2],None,[bins,bins,bins],[0,256,0,256,0,256])
hist = hist/np.max(hist)
# render everything
[ ax.plot([x],[y],[z],'.',markersize=max(hist[x,y,z]*100,6),color=color) for x,y,z,color in idxs if(hist[x][y][z]>0) ]
#[ ax.plot([x],[y],[z],'.',color=color) for x,y,z,color in idxs if(hist[x][y][z]>0) ]
ax.set_xlim3d(0, bins-1)
ax.set_ylim3d(0, bins-1)
ax.set_zlim3d(0, bins-1)
azim = (azim+0.5)%360
ax.view_init(elev=35, azim=azim)
########### convert matplotlib to SimpleCV image
canvas.draw()
renderer = canvas.get_renderer()
raw_data = renderer.tostring_rgb()
size = canvas.get_width_height()
surf = pg.image.fromstring(raw_data, size, "RGB")
figure = Image(surf)
############ All done
figure = figure.floodFill((0,0), tolerance=5,color=Color.WHITE)
result = figure.blit(img, pos=(20,20))
result.save(disp)
fig.clf()
示例13: plot_gamma_dist
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
#.........这里部分代码省略.........
u'FDP Gamma (estimée)']
else:
lg_labels = ['Measured data PDF', 'Gamma PDF (measured)',
'Gamma PDF (estimated)']
# Histogram
ax0.hist(Ymes, bins=20, color=c1, histtype='stepfilled', density=True,
alpha=0.25, ec=c1, label=lg_labels[0])
# Measured Gamma PDF
alpha, loc, beta = gamma.fit(Ymes)
x = np.arange(0.5, Xmax, 0.1)
ax0.plot(x, gamma.pdf(x, alpha, loc=loc, scale=beta), '-', lw=2,
alpha=1., color=c1, label=lg_labels[1])
# Predicted Gamma PDF
alpha, loc, beta = gamma.fit(Ypre)
x = np.arange(0.5, Xmax, 0.1)
ax0.plot(x, gamma.pdf(x, alpha, loc=loc, scale=beta), '--r',
lw=2, alpha=0.85, color=c2, label=lg_labels[2])
# ---- Axis Limits
ax0.axis(xmin=0, xmax=Xmax, ymax=1)
# ---- Labels
# Setup axis labels
if language == 'French':
ax0.set_xlabel(u'Précipitations totales journalières (mm)',
fontsize=18, labelpad=15)
ax0.set_ylabel('Probabilité', fontsize=18, labelpad=15)
else:
ax0.set_xlabel('Daily Total Precipitation (mm)', fontsize=18,
labelpad=15)
ax0.set_ylabel('Probability', fontsize=18, labelpad=15)
# Setup yticks labels
ax0.xaxis.set_ticks_position('bottom')
ax0.yaxis.set_ticks_position('left')
ax0.tick_params(axis='both', direction='out', labelsize=14)
ax0.tick_params(axis='both', which='minor', direction='out',
labelsize=14)
canvas.draw()
ylabels = []
for i, label in enumerate(ax0.get_yticks()):
if label >= 1:
ylabels.append('%d' % label)
elif label <= 10**-3:
ylabels.append('$\\mathdefault{10^{%d}}$' % np.log10(label))
else:
ylabels.append(str(label))
ax0.set_yticklabels(ylabels)
# ---- Legend
lg = ax0.legend(loc='upper right', frameon=False)
# ---- Wet Days Comparison --
# ---- Generate text
preWetDays = np.where(Ypre > 0)[0]
mesWetDays = np.where(Ymes > 0)[0]
f = len(preWetDays) / float(len(mesWetDays)) * 100
if f > 100:
if language == 'French':
msg = 'Nombre de jours pluvieux surestimé de %0.1f%%' % (f - 100)
else:
msg = 'Number of wet days overestimated by %0.1f%%' % (f - 100)
else:
if language == 'French':
msg = 'Nombre de jours pluvieux sous-estimé de %0.1f%%' % (100 - f)
else:
msg = 'Number of wet days underestimated by %0.1f%%' % (100 - f)
# ---- Get Legend Box Position and Extent
canvas.draw()
bbox = lg.get_window_extent(canvas.get_renderer())
bbox = bbox.transformed(ax0.transAxes.inverted())
dx, dy = 5/72., 5/72.
padding = mpl.transforms.ScaledTranslation(dx, dy, fig.dpi_scale_trans)
transform = ax0.transAxes + padding
ax0.text(0., 0., msg, transform=transform, va='bottom', ha='left')
# ---- Draw
fig.savefig(fname) # A canvas.draw() is included with this.
return canvas
示例14: plot_est_err
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_renderer [as 别名]
def plot_est_err(Ymes, Ypre, varName, fname, language='English'):
Ymax = np.ceil(np.max(Ymes)/10)*10
Ymin = np.floor(np.min(Ymes)/10)*10
fw, fh = 6, 6
fig = mpl.figure.Figure(figsize=(fw, fh))
canvas = FigureCanvas(fig)
# ---- Create Axes
leftMargin = 1. / fw
rightMargin = 0.25 / fw
bottomMargin = 0.8 / fh
topMargin = 0.25 / fh
x0 = leftMargin
y0 = bottomMargin
w0 = 1 - (leftMargin + rightMargin)
h0 = 1 - (bottomMargin + topMargin)
ax0 = fig.add_axes([x0, y0, w0, h0])
ax0.set_axisbelow(True)
ax0.grid(axis='both', color='0.', linestyle='--', linewidth=0.5,
dashes=[0.5, 3])
# ---- Plot
# Estimation Error
hscat, = ax0.plot(Ymes, Ypre, '.', mec='k', mfc='k', ms=12, alpha=0.35)
hscat.set_rasterized(True)
# 1:1 Line
dl = 12 # dashes length
ds = 6 # spacing between dashes
dew = 0.5 # dashes edge width
dlw = 1.5 # dashes line width
# Plot a white contour line
ax0.plot([Ymin, Ymax], [Ymin, Ymax], '-w', lw=dlw + 2 * dew, alpha=1)
# Plot a black dashed line
hbl, = ax0.plot([Ymin, Ymax], [Ymin, Ymax], 'k', lw=dlw,
dashes=[dl, ds], dash_capstyle='butt')
# ---- Text
# Calculate Statistics
RMSE = (np.mean((Ypre - Ymes) ** 2)) ** 0.5
MAE = np.mean(np.abs(Ypre - Ymes))
ME = np.mean(Ypre - Ymes)
r = np.corrcoef(Ypre, Ymes)[1, 0]
print('RMSE=%0.1f ; MAE=%0.1f ; ME=%0.2f ; r=%0.3f' %
(RMSE, MAE, ME, r))
Emax = np.min(Ypre - Ymes)
Emin = np.max(Ypre - Ymes)
print('Emax=%0.1f ; Emin=%0.1f' % (Emax, Emin))
# Generate and Plot Labels
if varName in ['Max Temp (deg C)', 'Mean Temp (deg C)',
'Min Temp (deg C)']:
units = u'°C'
elif varName in ['Total Precip (mm)']:
units = 'mm'
else:
units = ''
tcontent = [u'RMSE = %0.1f %s' % (RMSE, units),
u'MAE = %0.1f %s' % (MAE, units),
u'ME = %0.2f %s' % (ME, units),
u'r = %0.3f' % (r)]
tcontent = list(reversed(tcontent))
for i in range(len(tcontent)):
dx, dy = -10 / 72., 10 * (i+1) / 72.
padding = mpl.transforms.ScaledTranslation(dx, dy,
fig.dpi_scale_trans)
transform = ax0.transAxes + padding
ax0.text(0, 0, tcontent[i], ha='left', va='bottom', fontsize=16,
transform=transform)
# ---- Get Labels Win. Extents
hext, vext = np.array([]), np.array([])
renderer = canvas.get_renderer()
for text in ax0.texts:
bbox = text.get_window_extent(renderer)
bbox = bbox.transformed(ax0.transAxes.inverted())
hext = np.append(hext, bbox.width)
vext = np.append(vext, bbox.height)
# ---- Position Labels in Axes
x0 = 1 - np.max(hext)
y0 = 0
for i, text in enumerate(ax0.texts):
text.set_position((x0, y0))
#.........这里部分代码省略.........