这是我正在做的一个最小的例子,代码:
B = np.array([0.6383447,0.5271385,1.7721380,1.7817880])b_mean =平均值(B)ori_t = stats.ttest_1samp(B,0)[0]r1 = [1]plt.bar(R1,b_mean,宽度= …
问题是你在路过 r1 = [1] 作为文本的x位置。 r1 是一个不能用于指定文本位置的列表。 x 和 y 参数 plt.text 应该是标量。所以要么你写 x=1 或者你写 x=r1[0] 两者都是标量。我在答案中包含了缺失的导入,以使其完整。我也相应地调整了y限制。
r1 = [1]
r1
x
y
plt.text
x=1
x=r1[0]
来自 文档 :
x,y:标量 放置文本的位置。默认情况下,这是数据坐标。可以使用transform参数更改坐标系。
from scipy import stats import numpy as np import matplotlib.pyplot as plt B = np.array([0.6383447, 0.5271385, 1.7721380, 1.7817880]) b_mean = np.mean(B) ori_t = stats.ttest_1samp(B, 0)[0] r1 = [1] plt.bar(r1,b_mean,width=0.02, color="blue") plt.text(x=r1[0], y=b_mean+0.1, s=ori_t, size = 10) # plt.text(x=1, y=b_mean+0.1, s=ori_t, size = 10) plt.ylim(0, b_mean+0.2) plt.show()