Search code examples
pythonploterrorbar

Error bar in python:ErrorbarContainer object of 3 artists


I am trying to make an error plot but I get the error:

import numpy as np
import matplotlib.pyplot as plt

x = np.array([1, 2, 3])
y = np.array([17706973.57161736,  4605821.60887734,  2179197.59021156])
nor = np.array([1.21377113, 0.31571817, 0.14937884])
plt.errorbar(x, y, yerr = nor)

ErrorbarContainer object of 3 artists and the plot does not contain error bars. Any idea?


Solution

  • What are you getting is not an error, it is the output of plt.errorbar. The reason you do not see the bars is because the scale of the error is way smaller than the scale of the data you are plotting. In fact, if you make the errors larger you will see them:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.array([1, 2, 3])
    y = np.array([17706973.57161736,  4605821.60887734,  2179197.59021156])
    # Larger error.
    nor = np.array([1.21377113 * 5000000, 0.31571817 * 5000000, 0.14937884 * 5000000])
    plt.errorbar(x, y, yerr = nor)
    

    enter image description here