From 23d9b03861d18f8f41a3411f34b7e6047d2aedee Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Wed, 21 Sep 2022 18:12:04 +0200 Subject: [PATCH] DOC: Suppress IPython output in examples and tutorials where not needed By default, sphinx-gallery captures the last output of each code block and shows it in the generated html in yellow boxes. Especially in tutorials with a frequently interleaving code and text blocks this may appear confusing and reduces readability. In some cases, however, the output is desired (although it could always be replaced by printing). The global configuration is now changed to "capture nothing", for one tutorial with multiple desired outputs this is overridden in the file to show the output and in other cases with just one desired output it's converted to a call to print(). --- doc/conf.py | 1 + tutorials/intermediate/artists.py | 1 + tutorials/intermediate/autoscale.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/conf.py b/doc/conf.py index 7621a922a5b3..4b9dfdaddb1f 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -199,6 +199,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, 'subsection_order': gallery_order.sectionorder, 'thumbnail_size': (320, 224), 'within_subsection_order': gallery_order.subsectionorder, + 'capture_repr': (), } if 'plot_gallery=0' in sys.argv: diff --git a/tutorials/intermediate/artists.py b/tutorials/intermediate/artists.py index f76c62d8462c..22793ddd5fd0 100644 --- a/tutorials/intermediate/artists.py +++ b/tutorials/intermediate/artists.py @@ -115,6 +115,7 @@ class in the Matplotlib API, and the one you will be working with most Try creating the figure below. """ +# sphinx_gallery_capture_repr = ('__repr__',) import numpy as np import matplotlib.pyplot as plt diff --git a/tutorials/intermediate/autoscale.py b/tutorials/intermediate/autoscale.py index 0f4dda87d183..3b563510aa1f 100644 --- a/tutorials/intermediate/autoscale.py +++ b/tutorials/intermediate/autoscale.py @@ -26,7 +26,7 @@ # ------- # The default margin around the data limits is 5%: -ax.margins() +print(ax.margins()) ############################################################################### # The margins can be made larger using `~matplotlib.axes.Axes.margins`: