如何在我的 Python Pandas 箱线图中手动设置 Y 轴的最大值?

问题描述 投票:0回答:1

我正在查看 this 官方 Pandas 文档,其中说我可以在创建箱线图时指定“类 matplotlib.axes.Axes 的对象”。

如何格式化这个箱线图轴对象,以便我可以手动设置最大 Y 轴值?

我在这里看到了关于改变 Y 轴after创建箱线图的问题和答案,但这些对我没有用,我想在创建箱线图时设置 Y 轴最大值。

这是我目前的代码:

import pandas as pd    
prices= pd.read_csv('..\priceData.csv')
boxplot = prices.boxplot(column=['price'])

提前谢谢你!

python pandas matplotlib boxplot axes
1个回答
0
投票

获取

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
之后:

© www.soinside.com 2019 - 2024. All rights reserved.