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

Skip to content

Commit 19069e5

Browse files
committed
Merge pull request #2914 from astrofrog/fix-plot-directive-rcparams
Don't close figure if context and apply_rcparams are both set.
2 parents 0b5a34c + 7cfe8c8 commit 19069e5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ def _dummy_print(*arg, **kwarg):
554554
sys.stdout = stdout
555555
return ns
556556

557-
def clear_state(plot_rcparams):
558-
plt.close('all')
557+
def clear_state(plot_rcparams, close=True):
558+
if close:
559+
plt.close('all')
559560
matplotlib.rc_file_defaults()
560561
matplotlib.rcParams.update(plot_rcparams)
561562

@@ -635,9 +636,12 @@ def render_figures(code, code_path, output_dir, output_base, context,
635636
else:
636637
ns = {}
637638

639+
638640
for i, code_piece in enumerate(code_pieces):
641+
639642
if not context or config.plot_apply_rcparams:
640-
clear_state(config.plot_rcparams)
643+
clear_state(config.plot_rcparams, close=not context)
644+
641645
run_code(code_piece, code_path, ns, function_name)
642646

643647
images = []
@@ -661,7 +665,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
661665
results.append((code_piece, images))
662666

663667
if not context or config.plot_apply_rcparams:
664-
clear_state(config.plot_rcparams)
668+
clear_state(config.plot_rcparams, close=not context)
665669

666670
return results
667671

0 commit comments

Comments
 (0)