ann*_*irb 3 python matplotlib errorbar
我是 Stack Overflow 的新手,所以如果这是一个重复的问题或含糊不清,我深表歉意 - 我也是 Python 和一般编码的新手。
我想创建一个错误条形图,该图在高与低之间具有不相等的“错误限制”。
我将绘制一个月的平均温度,上误差需要是当月的最高温度,下误差需要是当月的最低温度。
我了解如何使用误差相等的误差线,但不了解如何使它们不相等。
已添加图片以供参考。我将用于绘制图表的列表的简短示例是:
temps_avg = [46, 49, 58, 69, 73, 79, 84]
temps_high = [78, 80, 82, 88, 88, 93, 101]
temps_low = [21, 29, 25, 48, 54, 62, 70]
Run Code Online (Sandbox Code Playgroud)
我想复制的条形图但没有错误条

您可以在 matplotlib 条形图的 yerr arg 中的元组中放置低错误限制和高错误限制:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.bar([0,1,2,3,4,5,6], temps_avg, yerr = (temps_low,temps_high))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2757 次 |
| 最近记录: |