Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c19ebd6

Browse files
authored
Merge pull request #14683 from anntzer/sphinxext-imageformat
MNT: For non-html output, let sphinx pick the best format.
2 parents dcff0d2 + caedd43 commit c19ebd6

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def split_code_at_show(text):
348348
TEMPLATE = """
349349
{{ source_code }}
350350
351-
{{ only_html }}
351+
.. only:: html
352352
353353
{% if source_link or (html_show_formats and not multi_image) %}
354354
(
@@ -384,29 +384,15 @@ def split_code_at_show(text):
384384
{{ caption }}
385385
{% endfor %}
386386
387-
{{ only_latex }}
387+
.. only:: not html
388388
389389
{% for img in images %}
390-
{% if 'pdf' in img.formats -%}
391-
.. figure:: {{ build_dir }}/{{ img.basename }}.pdf
390+
.. figure:: {{ build_dir }}/{{ img.basename }}.*
392391
{% for option in options -%}
393392
{{ option }}
394393
{% endfor %}
395394
396395
{{ caption }}
397-
{% endif -%}
398-
{% endfor %}
399-
400-
{{ only_texinfo }}
401-
402-
{% for img in images %}
403-
{% if 'png' in img.formats -%}
404-
.. image:: {{ build_dir }}/{{ img.basename }}.png
405-
{% for option in options -%}
406-
{{ option }}
407-
{% endfor %}
408-
409-
{% endif -%}
410396
{% endfor %}
411397
412398
"""
@@ -777,10 +763,6 @@ def run(arguments, content, options, state_machine, state, lineno):
777763
':%s: %s' % (key, val) for key, val in options.items()
778764
if key in ('alt', 'height', 'width', 'scale', 'align', 'class')]
779765

780-
only_html = ".. only:: html"
781-
only_latex = ".. only:: latex"
782-
only_texinfo = ".. only:: texinfo"
783-
784766
# Not-None src_link signals the need for a source link in the generated
785767
# html
786768
if j == 0 and config.plot_html_show_source_link:
@@ -794,9 +776,6 @@ def run(arguments, content, options, state_machine, state, lineno):
794776
build_dir=build_dir_link,
795777
source_link=src_link,
796778
multi_image=len(images) > 1,
797-
only_html=only_html,
798-
only_latex=only_latex,
799-
only_texinfo=only_texinfo,
800779
options=opts,
801780
images=images,
802781
source_code=source_code,

0 commit comments

Comments
 (0)