8000 Merge pull request #4702 from hamogu/fix_4702 · notmatthancock/matplotlib@f3e2fa1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f3e2fa1

Browse files
committed
Merge pull request matplotlib#4702 from hamogu/fix_4702
sphinxext/plot_directive does not accept a caption
2 parents 08cb2c0 + b38a951 commit f3e2fa1

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,6 @@ def render_figures(code, code_path, output_dir, output_base, context,
662662

663663

664664
def run(arguments, content, options, state_machine, state, lineno):
665-
# The user may provide a filename *or* Python code content, but not both
666-
if arguments and content:
667-
raise RuntimeError("plot:: directive can't have both args and content")
668-
669665
document = state_machine.document
670666
config = document.settings.env.config
671667
nofigs = 'nofigs' in options

lib/matplotlib/sphinxext/tests/test_tinypages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ def plot_file(num):
8383
with open(pjoin(self.html_dir, 'some_plots.html'), 'rt') as fobj:
8484
html_contents = fobj.read()
8585
assert_true('# Only a comment' in html_contents)
86+
# check plot defined in external file.
87+
assert_true(file_same(range_4, pjoin(self.html_dir, 'range4.png')))
88+
assert_true(file_same(range_6, pjoin(self.html_dir, 'range6.png')))
89+
# check if figure caption made it into html file
90+
assert_true('This is the caption for plot 15.' in html_contents)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from matplotlib import pyplot as plt
2+
3+
plt.figure()
4+
plt.plot(range(4))
5+
plt.show()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from matplotlib import pyplot as plt
2+
3+
4+
def range4():
5+
'''This is never be called if plot_directive works as expected.'''
6+
raise NotImplementedError
7+
8+
9+
def range6():
10+
'''This is the function that should be executed.'''
11+
plt.figure()
12+
plt.plot(range(6))
13+
plt.show()

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,16 @@ Plot 14 uses ``include-source``:
114114
:include-source:
115115

116116
# Only a comment
117+
118+
Plot 15 uses an external file with the plot commands and a caption:
119+
120+
.. plot:: range4.py
121+
122+
This is the caption for plot 15.
123+
124+
125+
Plot 16 uses a specific function in a file with plot commands:
126+
127+
.. plot:: range6.py range6
128+
129+

0 commit comments

Comments
 (0)
0