python - python:如何将 p 值重要性添加到 barplot
问题描述
下面我有一个条形图的代码,我还想显示这些图的 Pvalue significane。是否有任何简单的方法来指示这些条的统计显着性
import matplotlib.pyplot as plt
X= [-0.9384815619939103, 1.0755888058123153, 0.061274066731665564, 0.65064830688728]
x_labels = ['A' ,'B', 'C', 'D']
error = [0.23722952107696088, 0.25505883348061764, 0.26038015798295744, 0.26073839861422]
pvalue = [0.000076, 0.000025, 0.813956, 0.012581]
fig, ax = plt.subplots()
ax.bar(x_labels, X, width=0.4, align='center', yerr=error)
plt.show()
解决方案
这是另一种将 p 值放入情节图例的解决方案。在我看来,与在条形图上绘制 p 值相比,这更令人愉快。
import matplotlib.pyplot as plt
X= [-0.9384815619939103, 1.0755888058123153, 0.061274066731665564, 0.65064830688728]
x_labels = ['A' ,'B', 'C', 'D']
error = [0.23722952107696088, 0.25505883348061764, 0.26038015798295744, 0.26073839861422]
pvalue = [0.000076, 0.000025, 0.813956, 0.012581]
fig, ax = plt.subplots()
cont = ax.bar(x_labels, X, width=0.4, align='center', yerr=error)
for i, art in enumerate(cont):
art.set_color('C{}'.format(i))
ax.legend(cont.patches, [r'$p={:.6f}$'.format(pv) for pv in pvalue])
推荐阅读
- asp.net-core - AWSSDK.DynamoDBv2 的 Table.PutItemAsync 始终返回 null
- r - 有没有办法在 r 中将 2 位数的年份变成 4 位数的年份
- python - 如何将列添加到漂亮表作为第一列
- swift - 使用@EnvironmentObject 我得到:“不能分配给属性:'viewModel' 是一个只能获取的属性”
- c++ - C++|将用户输入存储到模板变量
- mysql - MySQL: ERROR 1822 (HY000) 无法添加外键约束。缺少约束索引
- c - 如何使用任务和依赖项将 C 代码程序转换为 OpenMP
- batch-file - 批处理脚本在 ssh 后停止并且没有继续
- python - 如何将以下 Python 字符串拆分为字符串列表?
- clojure - 如何在环中发送输入流作为响应?