pd.df.plot.box()和pd.df.boxplot()的区别

6
为什么pandas有两个绘制箱线图的函数: pandas.DataFrame.plot.box()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


1
答案可能会沿着“API膨胀”这条线,而不是更深入的东西。Pandas正在各个地方弃用一些东西。 - roganjosh
2个回答

3
两种方法都返回一个'matplotlib.axes._subplots.AxesSubplot'对象。显然,它们调用不同的pandas库的部分来执行。
其中一个后果是,pandas.DataFrame.plot.box()方法使用FramePlotMethods类,其中“grid = None”,而pandas.DataFrame.boxplot()默认情况下具有“grid = True”。您将在两个图表的背景线中注意到这一点。
此外,.boxplot()不能用于Series,而.plot()可以用于Series。

0

df.plot.box 不接受 column 关键字参数

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')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接