Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf7d34b

Browse files
committed
BF: plot_directive template to allow class+caption
1 parent8e13d3b commitaf7d34b

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

‎lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ def split_code_at_show(text):
344344
# Template
345345
# -----------------------------------------------------------------------------
346346

347-
348347
TEMPLATE="""
349348
{{ source_code }}
350349
@@ -379,9 +378,8 @@ def split_code_at_show(text):
379378
`{{ fmt }} <{{ dest_dir }}/{{ img.basename }}.{{ fmt }}>`__
380379
{%- endfor -%}
381380
)
382-
{%- endif -%}
383-
384-
{{ caption }}
381+
{%- endif %}
382+
{{ caption }} {# appropriate leading whitespace added beforehand #}
385383
{% endfor %}
386384
387385
.. only:: not html
@@ -392,7 +390,7 @@ def split_code_at_show(text):
392390
{{ option }}
393391
{% endfor %}
394392
395-
{{ caption }}
393+
{{ caption }} {# appropriate leading whitespace added beforehand #}
396394
{% endfor %}
397395
398396
"""
@@ -632,9 +630,12 @@ def run(arguments, content, options, state_machine, state, lineno):
632630

633631
options.setdefault('include-source',config.plot_include_source)
634632
if'class'inoptions:
635-
options['class']=options['class']+' plot-directive'
633+
# classes are parsed into a list of string, and output by simply
634+
# printing the list, abusing the fact that RST guarantees to strip
635+
# non-conforming characters
636+
options['class']= ['plot-directive']+options['class']
636637
else:
637-
options.setdefault('class','plot-directive')
638+
options.setdefault('class',['plot-directive'])
638639
keep_context='context'inoptions
639640
context_opt=Noneifnotkeep_contextelseoptions['context']
640641

‎lib/matplotlib/tests/test_sphinxext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ def plot_file(num):
5757
assertb'Plot 17 uses the caption option.'inhtml_contents
5858
# check if figure caption made it into html file
5959
assertb'This is the caption for plot 18.'inhtml_contents
60+
# check if the custom classes made it into the html file
61+
assertb'plot-directive my-class my-other-class'inhtml_contents
62+
# check that the multi-image caption is applied twice
63+
asserthtml_contents.count(b'This caption applies to both plots.')==2

‎lib/matplotlib/tests/tinypages/some_plots.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,23 @@ using the :caption: option:
141141

142142
..plot::range4.py
143143
:caption: This is the caption for plot 18.
144+
145+
Plot 19 uses shows that the "plot-directive" class is still appended, even if
146+
we request other custom classes:
147+
148+
..plot::range4.py
149+
:class: my-class my-other-class
150+
151+
Should also have a caption.
152+
153+
Plot 20 shows that the default template correctly prints the multi-image
154+
scenario:
155+
156+
..plot::
157+
:caption: This caption applies to both plots.
158+
159+
plt.figure()
160+
plt.plot(range(6))
161+
162+
plt.figure()
163+
plt.plot(range(4))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp