Skip to content

Commit 8d0c025

Browse files
jbrockmendeljreback
authored andcommitted
Define DataFrame plot methods in DataFrame (#17020)
1 parent f511d82 commit 8d0c025

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

pandas/core/frame.py

+9-25
Original file line numberDiff line numberDiff line change
@@ -5746,12 +5746,21 @@ def isin(self, values):
57465746
values).reshape(self.shape), self.index,
57475747
self.columns)
57485748

5749+
# ----------------------------------------------------------------------
5750+
# Add plotting methods to DataFrame
5751+
plot = base.AccessorProperty(gfx.FramePlotMethods, gfx.FramePlotMethods)
5752+
hist = gfx.hist_frame
5753+
boxplot = gfx.boxplot_frame
5754+
57495755

57505756
DataFrame._setup_axes(['index', 'columns'], info_axis=1, stat_axis=0,
57515757
axes_are_reversed=True, aliases={'rows': 0})
57525758
DataFrame._add_numeric_operations()
57535759
DataFrame._add_series_or_dataframe_operations()
57545760

5761+
ops.add_flex_arithmetic_methods(DataFrame, **ops.frame_flex_funcs)
5762+
ops.add_special_arithmetic_methods(DataFrame, **ops.frame_special_funcs)
5763+
57555764
_EMPTY_SERIES = Series([])
57565765

57575766

@@ -6097,28 +6106,3 @@ def _from_nested_dict(data):
60976106

60986107
def _put_str(s, space):
60996108
return ('%s' % s)[:space].ljust(space)
6100-
6101-
6102-
# ----------------------------------------------------------------------
6103-
# Add plotting methods to DataFrame
6104-
DataFrame.plot = base.AccessorProperty(gfx.FramePlotMethods,
6105-
gfx.FramePlotMethods)
6106-
DataFrame.hist = gfx.hist_frame
6107-
6108-
6109-
@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs)
6110-
def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0,
6111-
grid=True, figsize=None, layout=None, return_type=None, **kwds):
6112-
from pandas.plotting._core import boxplot
6113-
import matplotlib.pyplot as plt
6114-
ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
6115-
grid=grid, rot=rot, figsize=figsize, layout=layout,
6116-
return_type=return_type, **kwds)
6117-
plt.draw_if_interactive()
6118-
return ax
6119-
6120-
6121-
DataFrame.boxplot = boxplot
6122-
6123-
ops.add_flex_arithmetic_methods(DataFrame, **ops.frame_flex_funcs)
6124-
ops.add_special_arithmetic_methods(DataFrame, **ops.frame_special_funcs)

pandas/plotting/_core.py

+12
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,18 @@ def plot_group(keys, values, ax):
20342034
return result
20352035

20362036

2037+
@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs)
2038+
def boxplot_frame(self, column=None, by=None, ax=None, fontsize=None, rot=0,
2039+
grid=True, figsize=None, layout=None,
2040+
return_type=None, **kwds):
2041+
import matplotlib.pyplot as plt
2042+
ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
2043+
grid=grid, rot=rot, figsize=figsize, layout=layout,
2044+
return_type=return_type, **kwds)
2045+
plt.draw_if_interactive()
2046+
return ax
2047+
2048+
20372049
def scatter_plot(data, x, y, by=None, ax=None, figsize=None, grid=False,
20382050
**kwargs):
20392051
"""

0 commit comments

Comments
 (0)