matplotlib.backends.backend_pdf
#
一个 PDF Matplotlib 后端。
作者:Jouni K Seppänen <jks@iki.fi> 及其他。
- class matplotlib.backends.backend_pdf.FigureCanvasPdf(figure=None)[source]#
-
- draw()[source]#
渲染
Figure
。此方法必须遍历 Artist 树,即使没有产生输出,因为它会触发用户在将输出保存到磁盘之前可能希望访问的延迟工作。例如,计算限制、自动限制和刻度值。
- filetypes = {'pdf': '可移植文档格式'}#
- fixed_dpi = 72#
- get_default_filetype()[source]#
返回 `savefig` 默认文件格式,该格式在
rcParams["savefig.format"]
中指定(默认:'png'
)。返回的字符串不包含句点。此方法在仅支持单一文件类型的后端中被覆盖。
- class matplotlib.backends.backend_pdf.GraphicsContextPdf(file)[source]#
-
- capstyles = {'butt': 0, 'projecting': 2, 'round': 1}#
- commands = ((('_cliprect', '_clippath'), <function GraphicsContextPdf.clip_cmd>), (('_alpha', '_forced_alpha', '_effective_alphas'), <function GraphicsContextPdf.alpha_cmd>), (('_capstyle',), <function GraphicsContextPdf.capstyle_cmd>), (('_fillcolor',), <function GraphicsContextPdf.fillcolor_cmd>), (('_joinstyle',), <function GraphicsContextPdf.joinstyle_cmd>), (('_linewidth',), <function GraphicsContextPdf.linewidth_cmd>), (('_dashes',), <function GraphicsContextPdf.dash_cmd>), (('_rgb',), <function GraphicsContextPdf.rgb_cmd>), (('_hatch', '_hatch_color', '_hatch_linewidth'), <function GraphicsContextPdf.hatch_cmd>))#
- joinstyles = {'bevel': 2, 'miter': 0, 'round': 1}#
- class matplotlib.backends.backend_pdf.Op(*values)[source]#
基类:
Enum
PDF 运算符(非详尽列表)。
- class matplotlib.backends.backend_pdf.PdfFile(filename, metadata=None)[source]#
基类:
object
PDF 文件对象。
- 参数:
- filenamestr 或 类路径 或 类文件
输出目标;如果为字符串,将打开文件进行写入。
- metadatadict from strings to strings and dates
信息字典对象(参见 PDF 参考资料 10.2.1 节“文档信息字典”),例如:
{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}
。标准键包括 'Title'、'Author'、'Subject'、'Keywords'、'Creator'、'Producer'、'CreationDate'、'ModDate' 和 'Trapped'。'Creator'、'Producer' 和 'CreationDate' 的值已预定义。可以通过将它们设置为
None
来移除。
- addGouraudTriangles(points, colors)[source]#
添加一个高洛德三角形着色。
- 参数:
- pointsnp.ndarray
三角形顶点,形状为 (n, 3, 2),其中 n = 三角形数量,3 = 顶点,2 = x, y。
- colorsnp.ndarray
顶点颜色,形状为 (n, 3, 1) 或 (n, 3, 4),与点类似,但最后一维为 (灰度,) 或 (r, g, b, alpha)。
- 返回:
- 名称,引用
- dviFontName(dvifont)[source]#
给定一个 dvi 字体对象,返回一个适用于 Op.selectfont 的名称。如果尚未注册,此操作将在
self.dviFontInfo
中注册字体信息。
- class matplotlib.backends.backend_pdf.PdfPages(filename, keep_empty=<deprecated parameter>, metadata=None)[source]#
基类:
object
一个多页 PDF 文件。
备注
实际上,
PdfPages
是PdfFile
的一个薄包装器,旨在避免在使用savefig
时忘记格式参数而引起的混淆。示例
>>> import matplotlib.pyplot as plt >>> # Initialize: >>> with PdfPages('foo.pdf') as pdf: ... # As many times as you like, create a figure fig and save it: ... fig = plt.figure() ... pdf.savefig(fig) ... # When no figure is specified the current figure is saved ... pdf.savefig()
创建一个新的 PdfPages 对象。
- 参数:
- filenamestr 或 类路径 或 类文件
使用
PdfPages.savefig
绘制的图表将写入到此位置的文件中。当首次保存图形时,文件将被打开(覆盖同名旧文件)。- metadata字典,可选
信息字典对象(参见 PDF 参考资料 10.2.1 节“文档信息字典”),例如:
{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}
。标准键包括 'Title'、'Author'、'Subject'、'Keywords'、'Creator'、'Producer'、'CreationDate'、'ModDate' 和 'Trapped'。'Creator'、'Producer' 和 'CreationDate' 的值已预定义。可以通过将它们设置为
None
来移除。
- class matplotlib.backends.backend_pdf.Reference(id)[source]#
基类:
object
PDF 引用对象。
使用 PdfFile.reserveObject() 创建引用。
- class matplotlib.backends.backend_pdf.RendererPdf(file, image_dpi, height, width)[source]#
基类:
RendererPDFPSBase
- draw_gouraud_triangles(gc, points, colors, trans)[source]#
绘制一系列 Gouraud 三角形。
- 参数:
- gc
GraphicsContextBase
图形上下文。
- triangles_array(N, 3, 2) 类数组
N个三角形的 (x, y) 点数组。
- colors_array(N, 3, 4) 类数组
N个三角形每个点的 RGBA 颜色数组。
- transform
Transform
应用于点的仿射变换。
- gc
- draw_image(gc, x, y, im, transform=None)[source]#
绘制 RGBA 图像。
- 参数:
- gc
GraphicsContextBase
带有裁剪信息的图形上下文。
- x浮点数
从画布左侧开始的物理单位(即点或像素)距离。
- y浮点数
从画布底部开始的物理单位(即点或像素)距离。
- im(N, M, 4) array of
numpy.uint8
RGBA 像素数组。
- transform
Affine2DBase
当且仅当具体后端在编写时使
option_scale_image
返回True
时,仿射变换(即Affine2DBase
)_可能_会传递给draw_image
。变换的平移向量以物理单位(即点或像素)给出。请注意,变换不会覆盖 _x_ 和 _y_,并且必须在通过 _x_ 和 _y_ 平移结果_之前_应用(这可以通过将 _x_ 和 _y_ 添加到由 _transform_ 定义的平移向量来完成)。
- gc
- draw_markers(gc, marker_path, marker_trans, path, trans, rgbFace=None)[source]#
在 path 的每个顶点(不包括控制点)绘制一个标记。
基本(回退)实现会多次调用
draw_path
。后端可能希望覆盖此方法,以便只绘制标记一次并多次重用它。
- draw_path_collection(gc, master_transform, paths, all_transforms, offsets, offset_trans, facecolors, edgecolors, linewidths, linestyles, antialiaseds, urls, offset_position)[source]#
绘制一组 paths。
每个路径首先由 _all_transforms_ 中对应的条目(一个 (3, 3) 矩阵列表)变换,然后由 _master_transform_ 变换。接着,它们由 _offsets_ 中对应的条目平移,该条目首先由 _offset_trans_ 变换。
facecolors、edgecolors、linewidths、linestyles 和 antialiased 是设置相应属性的列表。
offset_position 现在未使用,但参数保留是为了向后兼容。
基本(回退)实现会多次调用
draw_path
。后端可能希望覆盖此方法,以便仅渲染每组路径数据一次,然后使用不同的偏移量、颜色、样式等多次引用该路径。提供了生成器方法_iter_collection_raw_paths
和_iter_collection
,以帮助(并标准化)跨后端实现。强烈建议使用这些生成器,以便可以全局更改draw_path_collection
的行为。
- draw_tex(gc, x, y, s, prop, angle, *, mtext=None)[source]#
绘制一个 TeX 实例。
- 参数:
- gc
GraphicsContextBase
图形上下文。
- x浮点数
文本在显示坐标中的 x 位置。
- y浮点数
文本基线在显示坐标中的 y 位置。
- sstr
TeX 文本字符串。
- prop
FontProperties
字体属性。
- angle浮点数
逆时针旋转角度(度)。
- mtext
Text
要渲染的原始文本对象。
- gc
- draw_text(gc, x, y, s, prop, angle, ismath=False, mtext=None)[source]#
绘制文本实例。
- 参数:
- gc
GraphicsContextBase
图形上下文。
- x浮点数
文本在显示坐标中的 x 位置。
- y浮点数
文本基线在显示坐标中的 y 位置。
- sstr
文本字符串。
- prop
FontProperties
字体属性。
- angle浮点数
逆时针旋转角度(度)。
- ismath布尔值 或 "TeX"
如果为 True,则使用 mathtext 解析器。
- mtext
Text
要渲染的原始文本对象。
- gc
备注
后端实现者注意事项
RendererBase.draw_text
也支持将“TeX”传递给 _ismath_ 参数以使用 TeX 渲染,但这对实际的渲染后端来说不是必需的,并且许多内置后端确实不支持此功能。相反,TeX 渲染由draw_tex
提供。
- get_image_magnification()[source]#
获取传递给
draw_image
的图像的放大因子。允许后端以与其它艺术家不同的分辨率处理图像。
- new_gc()[source]#
返回
GraphicsContextBase
的实例。
- class matplotlib.backends.backend_pdf.Stream(id, len, file, extra=None, png=None)[source]#
基类:
object
PDF 流对象。
此对象没有 pdfRepr 方法。相反,请调用 begin(),然后通过调用 write() 输出流内容,最后调用 end()。
- 参数:
- idint
流的对象 ID。
- lenReference or None
一个未使用的 Reference 对象,用于表示流的长度;None 表示使用内存缓冲区,以便长度可以内联。
- filePdfFile
写入流的底层对象。
- extradict from Name to anything, or None
要包含在流头中的额外键值对。
- pngdict or None
如果数据已进行 png 编码,则为解码参数。
- compressobj#
- extra#
- file#
- id#
- len#
- pdfFile#
- pos#