Skip to content

Commit 9598f77

Browse files
authored
DOC: Run doctests for pandas/plotting (#45019)
1 parent 149e193 commit 9598f77

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
7575
pandas/core \
7676
pandas/errors/ \
7777
pandas/io/ \
78+
pandas/plotting/ \
7879
pandas/tseries/ \
7980
pandas/util/ \
8081
pandas/_typing.py \

pandas/plotting/_core.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def hist_frame(
338338
>>> np.random.seed(1234)
339339
>>> df = pd.DataFrame(np.random.randn(10, 4),
340340
... columns=['Col1', 'Col2', 'Col3', 'Col4'])
341-
>>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3'])
341+
>>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3']) # doctest: +SKIP
342342
343343
Boxplots of variables distributions grouped by the values of a third
344344
variable can be created using the option ``by``. For instance:
@@ -381,7 +381,7 @@ def hist_frame(
381381
.. plot::
382382
:context: close-figs
383383
384-
>>> boxplot = df.boxplot(grid=False, rot=45, fontsize=15)
384+
>>> boxplot = df.boxplot(grid=False, rot=45, fontsize=15) # doctest: +SKIP
385385
386386
The parameter ``return_type`` can be used to select the type of element
387387
returned by `boxplot`. When ``return_type='axes'`` is selected,
@@ -591,14 +591,14 @@ def boxplot_frame_groupby(
591591
>>> data = np.random.randn(len(index),4)
592592
>>> df = pd.DataFrame(data, columns=list('ABCD'), index=index)
593593
>>> grouped = df.groupby(level='lvl1')
594-
>>> grouped.boxplot(rot=45, fontsize=12, figsize=(8,10))
594+
>>> grouped.boxplot(rot=45, fontsize=12, figsize=(8,10)) # doctest: +SKIP
595595
596596
The ``subplots=False`` option shows the boxplots in a single figure.
597597
598598
.. plot::
599599
:context: close-figs
600600
601-
>>> grouped.boxplot(subplots=False, rot=45, fontsize=12)
601+
>>> grouped.boxplot(subplots=False, rot=45, fontsize=12) # doctest: +SKIP
602602
"""
603603
plot_backend = _get_plot_backend(backend)
604604
return plot_backend.boxplot_frame_groupby(
@@ -987,6 +987,7 @@ def __call__(self, *args, **kwargs):
987987
988988
>>> s = pd.Series([1, 3, 2])
989989
>>> s.plot.line()
990+
<AxesSubplot:ylabel='Density'>
990991
991992
.. plot::
992993
:context: close-figs

pandas/plotting/_matplotlib/groupby.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ def create_iter_data_given_by(
4949
... [3, 4, np.nan, np.nan], [np.nan, np.nan, 5, 6]]
5050
>>> data = DataFrame(value, columns=mi)
5151
>>> create_iter_data_given_by(data)
52-
{'h1': DataFrame({'a': [1, 3, np.nan], 'b': [3, 4, np.nan]}),
53-
'h2': DataFrame({'a': [np.nan, np.nan, 5], 'b': [np.nan, np.nan, 6]})}
52+
{'h1': h1
53+
a b
54+
0 1.0 3.0
55+
1 3.0 4.0
56+
2 NaN NaN, 'h2': h2
57+
a b
58+
0 NaN NaN
59+
1 NaN NaN
60+
2 5.0 6.0}
5461
"""
5562

5663
# For `hist` plot, before transformation, the values in level 0 are values
@@ -96,10 +103,10 @@ def reconstruct_data_with_by(
96103
>>> df = DataFrame(d)
97104
>>> reconstruct_data_with_by(df, by='h', cols=['a', 'b'])
98105
h1 h2
99-
a b a b
100-
0 1 3 NaN NaN
101-
1 3 4 NaN NaN
102-
2 NaN NaN 5 6
106+
a b a b
107+
0 1.0 3.0 NaN NaN
108+
1 3.0 4.0 NaN NaN
109+
2 NaN NaN 5.0 6.0
103110
"""
104111
grouped = data.groupby(by)
105112

pandas/plotting/_misc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ def scatter_matrix(
123123
124124
>>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
125125
>>> pd.plotting.scatter_matrix(df, alpha=0.2)
126+
array([[<AxesSubplot:xlabel='A', ylabel='A'>,
127+
<AxesSubplot:xlabel='B', ylabel='A'>,
128+
<AxesSubplot:xlabel='C', ylabel='A'>,
129+
<AxesSubplot:xlabel='D', ylabel='A'>],
130+
[<AxesSubplot:xlabel='A', ylabel='B'>,
131+
<AxesSubplot:xlabel='B', ylabel='B'>,
132+
<AxesSubplot:xlabel='C', ylabel='B'>,
133+
<AxesSubplot:xlabel='D', ylabel='B'>],
134+
[<AxesSubplot:xlabel='A', ylabel='C'>,
135+
<AxesSubplot:xlabel='B', ylabel='C'>,
136+
<AxesSubplot:xlabel='C', ylabel='C'>,
137+
<AxesSubplot:xlabel='D', ylabel='C'>],
138+
[<AxesSubplot:xlabel='A', ylabel='D'>,
139+
<AxesSubplot:xlabel='B', ylabel='D'>,
140+
<AxesSubplot:xlabel='C', ylabel='D'>,
141+
<AxesSubplot:xlabel='D', ylabel='D'>]], dtype=object)
126142
"""
127143
plot_backend = _get_plot_backend("matplotlib")
128144
return plot_backend.scatter_matrix(
@@ -208,6 +224,7 @@ def radviz(frame, class_column, ax=None, color=None, colormap=None, **kwds):
208224
... }
209225
... )
210226
>>> pd.plotting.radviz(df, 'Category')
227+
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
211228
"""
212229
plot_backend = _get_plot_backend("matplotlib")
213230
return plot_backend.radviz(
@@ -266,6 +283,7 @@ def andrews_curves(
266283
... 'pandas/master/pandas/tests/io/data/csv/iris.csv'
267284
... )
268285
>>> pd.plotting.andrews_curves(df, 'Name')
286+
<AxesSubplot:title={'center':'width'}>
269287
"""
270288
plot_backend = _get_plot_backend("matplotlib")
271289
return plot_backend.andrews_curves(
@@ -325,6 +343,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
325343
326344
>>> s = pd.Series(np.random.uniform(size=100))
327345
>>> pd.plotting.bootstrap_plot(s)
346+
<Figure size 640x480 with 6 Axes>
328347
"""
329348
plot_backend = _get_plot_backend("matplotlib")
330349
return plot_backend.bootstrap_plot(
@@ -392,6 +411,7 @@ def parallel_coordinates(
392411
>>> pd.plotting.parallel_coordinates(
393412
... df, 'Name', color=('#556270', '#4ECDC4', '#C7F464')
394413
... )
414+
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
395415
"""
396416
plot_backend = _get_plot_backend("matplotlib")
397417
return plot_backend.parallel_coordinates(
@@ -440,13 +460,15 @@ def lag_plot(series, lag=1, ax=None, **kwds):
440460
>>> x = np.cumsum(np.random.normal(loc=1, scale=5, size=50))
441461
>>> s = pd.Series(x)
442462
>>> s.plot()
463+
<AxesSubplot:xlabel='Midrange'>
443464
444465
A lag plot with ``lag=1`` returns
445466
446467
.. plot::
447468
:context: close-figs
448469
449470
>>> pd.plotting.lag_plot(s, lag=1)
471+
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
450472
"""
451473
plot_backend = _get_plot_backend("matplotlib")
452474
return plot_backend.lag_plot(series=series, lag=lag, ax=ax, **kwds)
@@ -480,6 +502,7 @@ def autocorrelation_plot(series, ax=None, **kwargs):
480502
>>> spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
481503
>>> s = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
482504
>>> pd.plotting.autocorrelation_plot(s)
505+
<AxesSubplot:title={'center':'width'}, xlabel='Lag', ylabel='Autocorrelation'>
483506
"""
484507
plot_backend = _get_plot_backend("matplotlib")
485508
return plot_backend.autocorrelation_plot(series=series, ax=ax, **kwargs)

0 commit comments

Comments
 (0)