matplotlib.sphinxext.figmpl_directive
#
添加一个 figure-mpl
指令,这是 figure
的响应式版本。
这个实现与 .. figure::
非常相似,除了它还允许传递 srcset=
参数给图像标签,从而允许响应式分辨率图像。
没有特别的理由不能单独使用这个,但它旨在与 matplotlib.sphinxext.plot_directive 一起使用。
注意,目录组织与 .. figure::
略有不同。请参阅下面的 FigureMpl 文档。
- class matplotlib.sphinxext.figmpl_directive.FigureMpl(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[源代码][源代码]#
实现了一个指令,允许使用可选的 hidpi 图像。
用于与 conf.py 中的 plot_srcset 配置选项一起使用,并在 plot_directive.py 的 TEMPLATE 中设置。
例如:
.. figure-mpl:: plot_directive/some_plots-1.png :alt: bar :srcset: plot_directive/some_plots-1.png, plot_directive/some_plots-1.2x.png 2.00x :class: plot-directive
生成的 html 文件(位于
some_plots.html
)如下:<img src="sphx_glr_bar_001_hidpi.png" srcset="_images/some_plot-1.png, _images/some_plots-1.2x.png 2.00x", alt="bar" class="plot_directive" />
请注意,子目录的处理方式与 sphinx figure 指令所使用的方式不同:
.. figure-mpl:: plot_directive/nestedpage/index-1.png :alt: bar :srcset: plot_directive/nestedpage/index-1.png plot_directive/nestedpage/index-1.2x.png 2.00x :class: plot_directive
生成的html文件(位于
nestedpage/index.html
):<img src="../_images/nestedpage-index-1.png" srcset="../_images/nestedpage-index-1.png, ../_images/_images/nestedpage-index-1.2x.png 2.00x", alt="bar" class="sphx-glr-single-img" />
其中子目录被包含在图像名称中以确保唯一性。
- final_argument_whitespace = False#
最终参数可以包含空格吗?
- has_content = False#
指令可以有内容吗?
- option_spec = {'align': <function Image.align>, 'alt': <function unchanged>, 'caption': <function unchanged>, 'class': <function class_option>, 'height': <function length_or_unitless>, 'scale': <function nonnegative_int>, 'srcset': <function unchanged>, 'width': <function length_or_percentage_or_unitless>}#
选项名称到验证器函数的映射。
- optional_arguments = 2#
在必需参数之后的可选参数数量。
- required_arguments = 1#
所需指令参数的数量。