matplotlib.backends.backend_template
¶
一个完全功能化的,不做任何事情的后端,作为后端编写器的模板。它功能齐全,您可以选择它作为后端,例如:
import matplotlib
matplotlib.use("template")
你的程序会(应该!)运行时不会出错,但不会产生任何输出。这为后端编写器提供了一个起点;您可以有选择地实现绘图方法 (draw_path
, draw_image
等等)慢慢地看到你的形象变得栩栩如生,而不是在得到任何结果之前必须有一个全面的实现。
将此文件复制到Matplotlib源代码树之外的某个目录中,Python可以将其导入该目录(通过将该目录添加到 sys.path
或者将其打包为普通的Python包);如果后端可以作为 import my.backend
然后可以使用以下命令选择它:
import matplotlib
matplotlib.use("module://my.backend")
如果您的后端实现了对保存数字的支持(即 print_xyz
方法),可以将其注册为给定文件类型的默认处理程序:
from matplotlib.backend_bases import register_backend
register_backend('xyz', 'my_backend', 'XYZ File Format')
...
plt.savefig("figure.xyz")
-
matplotlib.backends.backend_template.
FigureCanvas
¶ alias of
matplotlib.backends.backend_template.FigureCanvasTemplate
-
class
matplotlib.backends.backend_template.
FigureCanvasTemplate
(figure)[源代码]¶ 基类:
matplotlib.backend_bases.FigureCanvasBase
图形渲染到的画布。调用draw和print fig方法,创建渲染器等。
注意:GUI模板希望将按钮按下、鼠标移动和按键事件连接到调用基类方法button_press_事件、button_release_事件、motion_notify_事件、key_press_事件和key_release_事件的函数。有关示例,请参见交互式后端的实现。
属性: -
filetypes
= {'eps': 'Encapsulated Postscript', 'foo': 'My magic Foo format', 'jpeg': 'Joint Photographic Experts Group', 'jpg': 'Joint Photographic Experts Group', 'pdf': 'Portable Document Format', 'pgf': 'PGF code for LaTeX', 'png': 'Portable Network Graphics', 'ps': 'Postscript', 'raw': 'Raw RGBA bitmap', 'rgba': 'Raw RGBA bitmap', 'svg': 'Scalable Vector Graphics', 'svgz': 'Scalable Vector Graphics', 'tif': 'Tagged Image File Format', 'tiff': 'Tagged Image File Format'}¶
-
get_default_filetype
()[源代码]¶ 返回中指定的默认savefig文件格式
rcParams["savefig.format"]
(default:'png'
) .返回的字符串不包含句点。此方法在仅支持单一文件类型的后端中被重写。
-
-
matplotlib.backends.backend_template.
FigureManager
¶ alias of
matplotlib.backends.backend_template.FigureManagerTemplate
-
class
matplotlib.backends.backend_template.
FigureManagerTemplate
(canvas, num)[源代码]¶ 基类:
matplotlib.backend_bases.FigureManagerBase
pyplot模式的Helper类,将所有内容打包成一个整洁的包。
对于非交互式后端,基类就足够了。
-
class
matplotlib.backends.backend_template.
GraphicsContextTemplate
[源代码]¶ 基类:
matplotlib.backend_bases.GraphicsContextBase
图形上下文提供颜色、线条样式等。。。有关将图形上下文属性(cap样式、连接样式、线宽、颜色)映射到特定后端的示例,请参阅cairo和postscript后端。在开罗,这是通过包装开罗。上下文对象,并使用字典将样式映射到gdk常量来转发相应的调用。在Postscript中,所有的工作都由渲染器完成,将线条样式映射到Postscript调用。
如果在呈现器级别(如postscript后端)执行映射更合适,则不需要重写任何GC方法。如果包装一个实例(如在cairo后端)并在这里进行映射更合适,则需要重写几个setter方法。
基本GraphicsContext将颜色存储为单位间隔上的RGB元组,例如(0.5、0.0、1.0)。您可能需要将其映射到适合您后端的颜色。
-
class
matplotlib.backends.backend_template.
RendererTemplate
(dpi)[源代码]¶ 基类:
matplotlib.backend_bases.RendererBase
渲染器处理绘制/渲染操作。
这是一个最小的什么都不做的类,可以用来开始编写新的后端。参考
backend_bases.RendererBase
方法文件。-
draw_image
(gc, x, y, im)[源代码]¶ 绘制RGBA图像。
参数: - gc :
GraphicsContextBase
GraphicsContextBase
包含剪辑信息的图形上下文。
- x标量
距离画布左侧的物理单位(即点或像素)。
- y标量
以物理单位(即点或像素)表示的与画布底部的距离。
- im类数组,shape=(N,M,4),数据类型=np.uint8公司
一组rgba像素。
- 转型 :
matplotlib.transforms.Affine2DBase
matplotlib.transforms.Affine2DBase
如果并且仅当具体的后端被写为
option_scale_image()
收益率True
,仿射变换(即Affine2DBase
) may 被传授给draw_image()
. 变换的平移向量以物理单位(即点或像素)给出。请注意,转换不会重写 x 和 y ,必须应用 之前 将结果转换为 x 和 y (这可以通过添加 x 和 y 到由定义的翻译矢量 转型 )
- gc :
-
draw_text
(gc, x, y, s, prop, angle, ismath=False, mtext=None)[源代码]¶ 绘制文本实例。
参数: - gc :
GraphicsContextBase
GraphicsContextBase
图形上下文。
- x浮动
文本在显示坐标中的x位置。
- y浮动
文本基线在显示坐标中的y位置。
- sSTR
文本字符串。
- prop :
matplotlib.font_manager.FontProperties
matplotlib.font_manager.FontProperties
字体属性。
- angle浮动
以度为单位的逆时针旋转角度。
- 多行文本 :
matplotlib.text.Text
matplotlib.text.Text
要呈现的原始文本对象。
笔记
后端实现者注意:
当您试图确定边界框是否正确时(这是使文本布局/对齐方式正常工作的原因),它有助于更改文本中的线条。py::
if 0: bbox_artist(self, renderer)
如果为1,则实际边界框将与文本一起打印。
- gc :
-
get_text_width_height_descent
(s, prop, ismath)[源代码]¶ Get the width, height, and descent (offset from the bottom to the baseline), in display coords, of the string s with
FontProperties
prop.
-
new_gc
()[源代码]¶ 返回的实例
GraphicsContextBase
.
-
-
matplotlib.backends.backend_template.
draw_if_interactive
()[源代码]¶ 对于映像后端-不需要。对于GUI后端-如果绘图应在交互式python模式下完成,则应重写此选项。
-
matplotlib.backends.backend_template.
new_figure_manager
(num, *args, FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)[源代码]¶ 创建新的地物管理器实例。