當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python matplotlib FigureMpl用法及代碼示例

本文簡要介紹 python 語言中 matplotlib.sphinxext.figmpl_directive.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 的模板中設置

例如:

.. 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-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" />

其中子目錄包含在圖像名稱中以確保唯一性。

相關用法


注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.sphinxext.figmpl_directive.FigureMpl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。