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

Appearance settings

Commit 4174eab

Browse filesBrowse files
committed
Enable sphinxext plot_directive to have args and caption
1 parent 6ee9a4d commit 4174eab
Copy full SHA for 4174eab

File tree

Expand file treeCollapse file tree

4 files changed

+28
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-4
lines changed

‎lib/matplotlib/sphinxext/plot_directive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/plot_directive.py
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,6 @@ def render_figures(code, code_path, output_dir, output_base, context,
651651

652652

653653
def run(arguments, content, options, state_machine, state, lineno):
654-
# The user may provide a filename *or* Python code content, but not both
655-
if arguments and content:
656-
raise RuntimeError("plot:: directive can't have both args and content")
657-
658654
document = state_machine.document
659655
config = document.settings.env.config
660656
nofigs = 'nofigs' in options

‎lib/matplotlib/sphinxext/tests/test_tinypages.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/tests/test_tinypages.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ 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, plot_file(15)))
88+
assert_true(file_same(range_6, plot_file(16)))
89+
assert_true(file_same(range_4, plot_file(17)))
90+
# check if figure caption made it into html file
91+
assert_true('This is the caption for plot 17.')
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from matplotlib import pyplot as plt
2+
3+
plt.figure()
4+
plt.plot(range(4))
5+
6+
def range6():
7+
plt.figure()
8+
plt.plot(range(6))

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

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/tests/tinypages/some_plots.rst
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ 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:
119+
120+
.. plot:: range4.py
121+
122+
Plot 16 uses a specific function in a file with plot commands:
123+
124+
.. plot:: range4.py range6
125+
126+
Plot 17 uses an external file and a caption:
127+
128+
.. plot:: range4.py
129+
130+
This is the caption for plot 17.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.