From aec938cb366d4fb44726e2bf7bf62ebdde3ae609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 21 Jul 2023 20:15:58 +0200 Subject: [PATCH 1/5] Examples plotting.table & plot_params --- ci/code_checks.sh | 2 -- pandas/plotting/_misc.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 702e7d28a36d8..44d61658ec036 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -79,9 +79,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.io.stata.StataReader.variable_labels \ pandas.io.stata.StataWriter.write_file \ pandas.plotting.deregister_matplotlib_converters \ - pandas.plotting.plot_params \ pandas.plotting.register_matplotlib_converters \ - pandas.plotting.table \ pandas.util.hash_array \ pandas.util.hash_pandas_object \ pandas_object \ diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 4c12a7ad01537..3e01baba2cf7b 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -43,6 +43,20 @@ def table(ax: Axes, data: DataFrame | Series, **kwargs) -> Table: Returns ------- matplotlib table object + + Examples + -------- + + .. plot:: + :context: close-figs + + >>> import matplotlib.pyplot as plt + >>> df = pd.DataFrame({'A':[1, 2], 'B':[3,4]}) + >>> fix, ax = plt.subplots() + >>> ax.axis('off') + >>> table = pd.plotting.table(ax, df, loc='center', + ... cellLoc='center', colWidths=list([.2, .2])) + (0.0, 1.0, 0.0, 1.0) """ plot_backend = _get_plot_backend("matplotlib") return plot_backend.table( @@ -552,6 +566,22 @@ class _Options(dict): Allows for parameter aliasing so you can just use parameter names that are the same as the plot function parameters, but is stored in a canonical format that makes it easy to breakdown into groups later. + + Examples + -------- + + .. plot:: + :context: close-figs + + >>> np.random.seed(42) + >>> df = pd.DataFrame({'A': np.random.randn(1000), + ... 'B': np.random.randn(1000)}, + ... index=pd.date_range("1/1/2000", periods=1000)) + >>> with pd.plotting.plot_params.use("x_compat", True): + ... df["A"].plot(color="r") + ... df["B"].plot(color="g") + + """ # alias so the names are same as plotting method parameter names From 834655e2c384b1835cc9f45874d9f2fdbfe5453e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 24 Jul 2023 11:20:40 +0200 Subject: [PATCH 2/5] Remove error on CI --- pandas/plotting/_misc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 3e01baba2cf7b..757abc5932f02 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -56,7 +56,6 @@ def table(ax: Axes, data: DataFrame | Series, **kwargs) -> Table: >>> ax.axis('off') >>> table = pd.plotting.table(ax, df, loc='center', ... cellLoc='center', colWidths=list([.2, .2])) - (0.0, 1.0, 0.0, 1.0) """ plot_backend = _get_plot_backend("matplotlib") return plot_backend.table( From a85429f2224c549c6ed10507c9c7de59d4ba0260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 24 Jul 2023 12:36:31 +0200 Subject: [PATCH 3/5] less data for plot_parms --- pandas/plotting/_misc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 757abc5932f02..11dab36b139c8 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -56,6 +56,7 @@ def table(ax: Axes, data: DataFrame | Series, **kwargs) -> Table: >>> ax.axis('off') >>> table = pd.plotting.table(ax, df, loc='center', ... cellLoc='center', colWidths=list([.2, .2])) + (0.0, 1.0, 0.0, 1.0) """ plot_backend = _get_plot_backend("matplotlib") return plot_backend.table( @@ -573,9 +574,10 @@ class _Options(dict): :context: close-figs >>> np.random.seed(42) - >>> df = pd.DataFrame({'A': np.random.randn(1000), - ... 'B': np.random.randn(1000)}, - ... index=pd.date_range("1/1/2000", periods=1000)) + >>> df = pd.DataFrame({'A': np.random.randn(10), + ... 'B': np.random.randn(10)}, + ... index=pd.date_range("1/1/2000", + ... freq='4MS', periods=10)) >>> with pd.plotting.plot_params.use("x_compat", True): ... df["A"].plot(color="r") ... df["B"].plot(color="g") From 83dcc8f7f40a0e1765cfcad9382ce9569439eadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 24 Jul 2023 13:43:24 +0200 Subject: [PATCH 4/5] correcting table --- pandas/plotting/_misc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 11dab36b139c8..4ed18d4ac5062 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -51,12 +51,12 @@ def table(ax: Axes, data: DataFrame | Series, **kwargs) -> Table: :context: close-figs >>> import matplotlib.pyplot as plt - >>> df = pd.DataFrame({'A':[1, 2], 'B':[3,4]}) + >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) >>> fix, ax = plt.subplots() >>> ax.axis('off') - >>> table = pd.plotting.table(ax, df, loc='center', - ... cellLoc='center', colWidths=list([.2, .2])) (0.0, 1.0, 0.0, 1.0) + >>> table = pd.plotting.table(ax, df, loc='center', + ... cellLoc='center', colWidths=list([.2, .2])) """ plot_backend = _get_plot_backend("matplotlib") return plot_backend.table( From 4f66b06fc7e1c0ec6e51bfee639d3a92bcb4eb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 24 Jul 2023 14:31:38 +0200 Subject: [PATCH 5/5] fix plot_params error on CI --- pandas/plotting/_misc.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 4ed18d4ac5062..f862e49071cae 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -579,10 +579,8 @@ class _Options(dict): ... index=pd.date_range("1/1/2000", ... freq='4MS', periods=10)) >>> with pd.plotting.plot_params.use("x_compat", True): - ... df["A"].plot(color="r") - ... df["B"].plot(color="g") - - + ... _ = df["A"].plot(color="r") + ... _ = df["B"].plot(color="g") """ # alias so the names are same as plotting method parameter names