From de6d76e7db42a72957094d2c3a95c1903d30a88f Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 6 Mar 2018 16:20:15 +0100 Subject: [PATCH 1/2] DOC: enable matplotlib plot_directive to include figures in docstrings --- doc/source/conf.py | 9 +++++++++ pandas/plotting/_core.py | 8 ++++++++ 2 files changed, 17 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..533e3259cf7c2 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2537,6 +2537,14 @@ def line(self, **kwds): Returns ------- axes : matplotlib.AxesSubplot or np.array of them + + Examples + -------- + + .. plot:: + + >>> s = pd.Series([1, 3, 2]) + >>> s.plot.line() """ return self(kind='line', **kwds) From 7b15c02f6333aed5dee6e827422c03ed339812a6 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 6 Mar 2018 16:25:44 +0100 Subject: [PATCH 2/2] add close-figs context --- pandas/plotting/_core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 533e3259cf7c2..98fdcf8f94ae0 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2542,6 +2542,7 @@ def line(self, **kwds): -------- .. plot:: + :context: close-figs >>> s = pd.Series([1, 3, 2]) >>> s.plot.line()