在 Matplotlib 中不影响标记的透明误差线


要在不影响 matplotlib 中标记的情况下创建透明误差线,我们可以采取以下步骤:

步骤

  • 设置图形大小并调整子图之间的页边距。

  • 创建数据列表 x、y 和 z。

  • 初始化变量 error_bar_width=5

  • 将 y 与 x 绘制为带有附加误差线的线和/或标记。

  • 设置柱和上限的 alpha 值。

  • 使用 show() 方法显示图形。

示例

from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = [1, 3, 5, 7]
y = [1, 3, 5, 7]
z = [4, 5, 1, 4]

error_bar_width = 5

markers, caps, bars = plt.errorbar(x, y, z, capsize=5, elinewidth=error_bar_width,
   markeredgewidth=7, fmt='o', ecolor='black', capthick=2)
[bar.set_alpha(0.5) for bar in bars]
[cap.set_alpha(0.5) for cap in caps]

plt.show()

结果

将产生以下输出 -

更新于: 02-Feb-2022

2K+ 浏览

启动你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.