本文整理汇总了Python中matplotlib.backends.backend_pdf.PdfPages.infodict()['Title']方法的典型用法代码示例。如果您正苦于以下问题:Python PdfPages.infodict()['Title']方法的具体用法?Python PdfPages.infodict()['Title']怎么用?Python PdfPages.infodict()['Title']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_pdf.PdfPages
的用法示例。
在下文中一共展示了PdfPages.infodict()['Title']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_pdf
# 需要导入模块: from matplotlib.backends.backend_pdf import PdfPages [as 别名]
# 或者: from matplotlib.backends.backend_pdf.PdfPages import infodict()['Title'] [as 别名]
def export_pdf(self, filename, title="default", subtitle="default", include_cube_slice=True):
"""
Create a standardized one or two -page PDF of the current figures
Filename is e.g. "export1.pdf"
Title gets put on every figure in the PDF
Set include_cube_slice to False to export only the dendrogram
If include_cube_slide is true, the cube view will be exported,
at the Z value currently visible in the viewer.
"""
pp = PdfPages(filename)
# Figure out the titles and subtitles
cube_subtitle = None # This gets prepended to the subitle of the cube only, not the dendrogram
if title is "default":
# Default title:
title = "Dendrogram from {obj} {line}".format(obj=self.cube.object_name, line=self.cube.line_name)
if subtitle is "default":
subtitle = "Dendrogram parameters: min. flux {f}, min. npix {n:.0f}, min. delta {d}".format(
f=self.dendro_view.dendrogram.min_flux,
n=self.dendro_view.dendrogram.min_npix,
d=self.dendro_view.dendrogram.min_delta,
)
if include_cube_slice:
if self.cube.has_coords:
cube_subtitle = "@ {v:.2f} km/s (z={z}). {rest}".format(
v=self.cube.velocity_at(self.cube_view.z),
z=self.cube_view.z,
rest=subtitle,
)
else:
cube_subtitle = "@ z={z}. {rest}".format(z=self.cube_view.z, rest=subtitle)
export_size = (10,7.5) # in inches
if include_cube_slice:
cfig = self.cube_view.fig
self.cube_view._check_redraw()
old_size_cfig = (cfig.get_figwidth(), cfig.get_figheight())
cfig.set_size_inches(*export_size)
if title: ctitle = cfig.suptitle(title, weight='heavy', size='large')
if cube_subtitle: ctitle2 = cfig.suptitle(cube_subtitle, y=0.95)
pp.savefig(cfig)
# Reset the figure to how it was before:
if title: ctitle.set_visible(False) # Closest we can come to deleting these titles
if cube_subtitle: ctitle2.set_visible(False)
cfig.set_figwidth(old_size_cfig[0])
cfig.set_figheight(old_size_cfig[1])
# Now export the dendrogram figure:
dfig = self.dendro_view.fig
#old_size_dfig = dfig.get_size_inches()
old_size_dfig = (dfig.get_figwidth(), dfig.get_figheight())
dfig.set_size_inches(*export_size)
if title: dtitle = dfig.suptitle(title, weight='heavy', size='large')
if subtitle: dtitle2 = dfig.suptitle(subtitle, y=0.95)
pp.savefig(self.dendro_view.fig)
# Reset the figure to how it was before:
if title: dtitle.set_visible(False)
if subtitle: dtitle2.set_visible(False)
#dfig.set_size_inches(old_size_dfig)
dfig.set_figwidth(old_size_dfig[0])
dfig.set_figheight(old_size_dfig[1])
# Finalize the PDF:
if title:
pp.infodict()['Title'] = title
pp.close()
pp = None
# Now the draw() method must be called, or some of the dendrogram
# plot artists will cache the PDF renderer and cause bugs, due to
# the dendro_view's special handling of rendering
self.dendro_view.fig.canvas.draw()