gpt4 book ai didi

python - Pandas 箱线图中的 Xtick 频率

转载 作者:行者123 更新时间:2023-11-28 18:58:14 26 4
gpt4 key购买 nike

我正在使用 pandas groupby 使用条形图绘制风速与方向的关系图。然而,由于太多的风向值彼此接近,x 轴不可读。

我已经尝试了 oc_params ax.set_xticks 但我的 x 轴为空或修改后的 x 轴具有不同的值

我的数据框的头部

    Kvit_TIU     dir_cat  
0 0.064740 14
1 0.057442 15
2 0.056750 15
3 0.069002 17
4 0.068464 17
5 0.067057 17
6 0.071901 12
7 0.050464 5
8 0.066165 1
9 0.073993 27
10 0.090784 34
11 0.121366 33
12 0.087172 34
13 0.066197 30
14 0.073020 17
15 0.071784 16
16 0.081699 17
17 0.088014 14
18 0.076758 14
19 0.078574 14

我使用 groupby = dir_cat 创建了一个箱线图

fig = plt.figure() # create the canvas for plotting
ax1 = plt.subplot(1,1,1)
ax1 = df_KvTr10hz.boxplot(column='Kvit_TIU', by='dir_cat', showfliers=False, showmeans=True)
ax1.set_xticks([30,90, 180,270, 330])

我想以较低的频率绘制 x 轴。以便情节可读 unreadable plot using ax1.set_xticks

enter image description here

enter image description here

最佳答案

 ax1 = df_KvTr10hz.dropna().boxplot(column='Kvit_TIU', by='dir_cat', showfliers=False, showmeans=True)

编辑:使用 OP 示例数据框

sample

但是,如果我们用 NaN 替换 'dir_cat'>=30Kvit_TIU

samplewithNaN

关于python - Pandas 箱线图中的 Xtick 频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55727441/

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