简体   繁体   中英

Python print error bar with only 3 values (Min, Max and the current value)

How to display a kind of errorbar with only 3 Values : For example :

Max = 20 Min = 10 Current = 15

Output excepted : 在此处输入图像描述

The following is not working :

ax.errorbar([0,1], [10,20], yerr=15, fmt='o', color='black',
             ecolor='lightgray', elinewidth=3, capsize=0);

在此处输入图像描述

What am I doing wrong ?

See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)

y = x + 15
y_err_min = y - 5
y_err_max = y + 5

y_err = np.stack([y - y_err_min, y_err_max - y])

fig = plt.figure()
plt.errorbar(x, y, yerr=y_err)

在此处输入图像描述


For your specific problem, you can use the code below:

import numpy as np
import matplotlib.pyplot as plt

x = 0
y = 15
y_err = [[5], [5]]

fig = plt.figure()
plt.errorbar(x, y, yerr=y_err, marker='o', markerfacecolor='blue', markeredgecolor='blue', linestyle='-', color='red', capsize=10)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM