Difference between pd.df.plot.box() and pd.df.boxplot()

Viewed 829

Why pandas has two funcitons for Boxplot : pandas.DataFrame.plot.box() and pandas.DataFrame.boxplot() ?

df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
df.plot.box()

enter image description here

df.boxplot()

enter image description here

2 Answers

Both return a 'matplotlib.axes._subplots.AxesSubplot' object. Obviously, they are calling upon different parts of the pandas library to execute.

One of the consequences of this is that the pandas.DataFrame.plot.box() method uses the FramePlotMethods class where "grid = None" and pandas.DataFrame.boxplot() has "grid = True" by default. You'll notice this in the background lines in your two charts.

Additionally, .boxplot() can't be used on a Series, whereas .plot's can.

df.plot.box does not accept the column keyword argument

to_plot = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])

# This line will error:
# to_plot.plot.box(column='B')

# This line will not error, will work:
to_plot.boxplot(column='B')
Related