首页 > 解决方案 > 在 python 中更改 TukeyHSD 测试结果图中的 axys 格式

问题描述

我正在使用来自 statsmodels.stats.multicomp 的函数 MultiComparison 运行 TukeyHSD 测试,然后绘制结果。Everythink OK,但 X axys 被格式化为 Int 数字。我需要将格式更改为具有 2 个十进制大小写的浮点数。另外,如果我可以在同一个图中显示所有图和几个子图,那就太好了。

我要寄样品

import pandas as pd     
import matplotlib.pyplot as plt from    
statsmodels.stats.multicomp import MultiComparison

df = pd.read_excel('datafile.xlsx', 'data', header=0)

    Treatment   Assesment   Evaluation
0   1   1   14.61
1   1   1   11.41
2   1   1   15.89
3   1   1   15.24
4   1   1   11.00
5   2   1   12.87
6   2   1   11.32
7   2   1   17.74
8   2   1   13.00
9   2   1   13.90
10  3   1   15.83
11  3   1   14.97
12  3   1   15.81
13  3   1   18.66
14  3   1   14.06
15  4   1   16.32
16  4   1   14.54
17  4   1   16.95
18  4   1   13.60
19  4   1   14.36
20  1   2   17.57
21  1   2   21.81
22  1   2   17.80
23  1   2   17.00
24  1   2   18.74
25  2   2   18.18
26  2   2   20.66
27  2   2   19.99
28  2   2   16.80
29  2   2   18.22
30  3   2   19.35
31  3   2   19.84
32  3   2   23.38
33  3   2   20.47
34  3   2   21.42
35  4   2   25.52
36  4   2   20.50
37  4   2   20.18
38  4   2   19.97
39  4   2   19.60
40  1   3   17.35
41  1   3   23.96
42  1   3   17.83
43  1   3   23.21
44  1   3   22.53
45  2   3   22.83
46  2   3   23.79
47  2   3   20.70
48  2   3   24.28
49  2   3   21.16
50  3   3   28.41
51  3   3   25.96
52  3   3   26.33
53  3   3   26.71
54  3   3   29.21
55  4   3   23.13
56  4   3   30.12
57  4   3   23.61
58  4   3   27.42
59  4   3   29.74

Asses = df['Assesment'].unique()

for As in Asses:
    dfAs = df.loc[df['Assesment']==As]
    Tukey = MultiComparison(dfAs['Evaluation'],dfAs['Treatment'])
    results = Tukey.tukeyhsd(alpha=0.25)
    fig, ax = plt.subplots()
    results.plot_simultaneous(comparison_name=1, ax=ax, xlabel='Values', ylabel='Treatments')
    plt.title('Assesment ' + str(As))

结果是 3 个单独 的数字 评估结果 1

评估结果 2

评估结果 3

标签: pythontukey

解决方案


推荐阅读