gpt4 book ai didi

python - 使用 Pandas 的箱线图

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:25 24 4
gpt4 key购买 nike

尝试为 pandas 数据框绘制箱形图,但 x 轴列名称似乎不清晰。

import matplotlib.pyplot as plt
pd.set_option('display.mpl_style', 'default')
fig, ax1 = plt.subplots()
%matplotlib inline
df.boxplot(column = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver','avg_surge','surge_pct','trips_in_first_30_days','weekday_pct'])

下面是输出

image

如何解决此问题以使 x 轴列显示清晰

最佳答案

我想你需要参数 rot:

cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']

df.boxplot(column=cols, rot=90)

示例:

np.random.seed(100)
cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']
df = pd.DataFrame(np.random.rand(10, 7), columns=cols)
df.boxplot(column=cols, rot=90)

graph

关于python - 使用 Pandas 的箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43384268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com