matplotlib.sphinxext.figmpl_directive
#
添加一个 figure-mpl
指令,它是 figure
的响应式版本。
此实现与 .. figure::
非常相似,不同之处在于它还允许将 srcset=
参数传递给图像标签,从而允许响应式分辨率图像。
虽然没有特别的原因不能单独使用,但它旨在与 matplotlib.sphinxext.plot_directive 配合使用。
请注意,目录组织与 Sphinx 的 figure 指令略有不同。请参阅下面的 FigureMpl 文档。
- class matplotlib.sphinxext.figmpl_directive.FigureMpl(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]#
实现一个指令,以允许可选的高清图像。
旨在与 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#
必需指令参数的数量。