我用条形图来表示每组的数据。这些条中的一些彼此显著不同。如何在条形图中指出显著性差异?
import numpy as np
import matplotlib.pyplot as plt
menMeans = (5, 15, 30, 40)
menStd = (2, 3, 4, 5)
ind = np.arange(4) # the x locations for the groups
width=0.35
p1 = plt.bar(ind, menMeans, width=width, color='r', yerr=menStd)
plt.xticks(ind+width/2., ('A', 'B', 'C', 'D') )
我的目标是
4条答案
按热度按时间azpvetkf1#
上面的答案启发我自己写了一个小而灵活的函数:
这允许我得到一些相对简单的漂亮注解,例如:
ymzxtsji2#
我在这里做了几件事情,我建议在处理复杂的情节时。将自定义格式提取到字典中,当您想要更改参数时,它使生活变得简单-并且您可以将此字典传递给多个图。我还编写了一个自定义函数来
annotate
itervalues,作为奖励,如果你真的想的话,它可以在(A,C)
之间进行注解(我坚持我的评论,这不是正确的视觉方法)。一旦数据发生变化,它可能需要一些调整,但这应该会让你走上正确的轨道。camsedfj3#
如果你正在使用matplotlib并寻求boxplot注解,请使用我的代码作为函数:
统计标注
其中'x1'和'x2'是您要比较的两列,'ARRAY'是您用于说明箱线图的列表列表。并且,'TXT'是您的文本,如字符串格式的p值或显着/不显着。
因此,请使用以下命令调用它:
ecfdbz9o4#
pandas dataframe的分组条形图
注解条形图之间的显著差异
我已经修改了@ cheresmate的解决方案,以便在输入中也接收pandas dataframes。此功能已使用
matplotlib 3.5.1
进行测试所以函数的输入应该是这样的。
结果将保存到磁盘的图片如下