From 5782ab8325c687018baee6dc64b2a466bfca8a66 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 7 Mar 2018 14:57:17 +0100 Subject: [PATCH] DOC: enable matplotlib plot_directive to include figures in docstrings (#20015) --- doc/source/conf.py | 9 +++++++++ pandas/plotting/_core.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/source/conf.py b/doc/source/conf.py index c81d38db05cca..46249af8a5a56 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -63,6 +63,7 @@ 'ipython_sphinxext.ipython_console_highlighting', # lowercase didn't work 'IPython.sphinxext.ipython_console_highlighting', + 'matplotlib.sphinxext.plot_directive', 'sphinx.ext.intersphinx', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', @@ -85,6 +86,14 @@ if any(re.match("\s*api\s*", l) for l in index_rst_lines): autosummary_generate = True +# matplotlib plot directive +plot_include_source = True +plot_formats = [("png", 90)] +plot_html_show_formats = False +plot_html_show_source_link = False +plot_pre_code = """import numpy as np +import pandas as pd""" + # Add any paths that contain templates here, relative to this directory. templates_path = ['../_templates'] diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index b15c5271ae321..98fdcf8f94ae0 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2537,6 +2537,15 @@ def line(self, **kwds): Returns ------- axes : matplotlib.AxesSubplot or np.array of them + + Examples + -------- + + .. plot:: + :context: close-figs + + >>> s = pd.Series([1, 3, 2]) + >>> s.plot.line() """ return self(kind='line', **kwds)