Change the error bar color in Matplotlib

Python

Matplotlib

Errorbar

Change color

Luc B.

Python

Matplotlib

Error Bar

When using error bars to express uncertainty, changing the error bar color so it's different from the data marker can make the visualization easier to interpret.

Code Example

To change the error bar color, use the ecolor parameter to plt.errorbar().

import matplotlib.pyplot as plt

x_values = [20, 16, 12, 19, 18, 22, 14]
y_values = [1, 0.77, 0.67, 0.85, 0.78, 1.05, 0.63]
y_err = [0.3, 0.2, 0.4, 0.5, 0.3, 0.2, 0.3]

# Change the error bar color here
plt.errorbar(x_values, y_values, yerr=y_err, ecolor="red", fmt=".")

plt.show()

png

Supported color values are documented in the matplotlib color docs.