我正在查看 this 官方 Pandas 文档,其中说我可以在创建箱线图时指定“类 matplotlib.axes.Axes 的对象”。
如何格式化这个箱线图轴对象,以便我可以手动设置最大 Y 轴值?
我在这里看到了关于改变 Y 轴after创建箱线图的问题和答案,但这些对我没有用,我想在创建箱线图时设置 Y 轴最大值。
这是我目前的代码:
import pandas as pd
prices= pd.read_csv('..\priceData.csv')
boxplot = prices.boxplot(column=['price'])
提前谢谢你!
获取
Axes
返回的boxplot
并使用:
xmin, xmax = [-5, 5]
ymin, ymax = [-5, 5]
boxplot = prices.boxplot(column=['price'])
boxplot.set_xlim([xmin, xmax])
boxplot.set_ylim([ymin, ymax])
boxplot
来自文档:
import pandas as pd
import numpy as np
np.random.seed(1234)
df = pd.DataFrame(np.random.randn(10, 4),
columns=['Col1', 'Col2', 'Col3', 'Col4'])
boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3'])
在
set_xlim
和set_ylim
之后: