Use error bars in a Matplotlib scatter plot Last Updated : 19 Apr, 2025 Comments Improve Suggest changes Like Article Like Report When visualizing data, error bars provide a great way to indicate variability or uncertainty in your measurements. In this article, we’ll explore how to create scatter plots with error bars using Matplotlib's errorbar() function.Syntaxmatplotlib.pyplot.errorbar( x, y, yerr=None, xerr=None, fmt='', ecolor=None, elinewidth=None, capsize=None, barsabove=False, errorevery=1, capthick=None, **kwargs)Parameters: x, y: Coordinates of data points.xerr, yerr: Errors in the x or y directions.fmt: Format string for data points (e.g., 'o' for circles).ecolor: Color of error bars.capsize: Size of the cap on error bars.elinewidth: Line width of error bars.Example 1: Adding Some error in a 'y' value. Python import matplotlib.pyplot as plt a = [1, 3, 5, 7] b = [11, -2, 4, 19] plt.scatter(a, b) c = [1, 3, 2, 1] plt.errorbar(a, b, yerr=c, fmt="o") plt.show() Output:Example 2: Adding Some errors in the 'x' value. Python import matplotlib.pyplot as plt a = [1, 3, 5, 7] b = [11, -2, 4, 19] plt.scatter(a, b) c = [1, 3, 2, 1] plt.errorbar(a, b, xerr=c, fmt="o") plt.show() Output:Example 3: Adding error in x & y Python import matplotlib.pyplot as plt a = [1, 3, 5, 7] b = [11, -2, 4, 19] plt.scatter(a, b) c = [1, 3, 2, 1] d = [1, 3, 2, 1] plt.errorbar(a, b, xerr=c, yerr=d, fmt="o", color="r") plt.show() Output:Example 4: Adding variable error in x and y. Python import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [1, 2, 1, 2, 1] x_err = 0.5 y_err_min = [0.1, 0.5, 0.9, 0.1, 0.9] y_err_max = [0.2, 0.4, 0.6, 0.4, 0.2] # Asymmetric error bars y_err = [y_err_min, y_err_max] plt.errorbar(x, y, xerr=x_err, yerr=y_err, fmt='o') plt.title("Asymmetric Error Bars") plt.show() Output:Refer to Matplotlib for a better understanding. Comment More infoAdvertise with us Next Article Use error bars in a Matplotlib scatter plot S skrg141 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Create a stacked bar plot in Matplotlib In this article, we will learn how to Create a stacked bar plot in Matplotlib. Let's discuss some concepts: Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure wi 3 min read Add error bars to a Matplotlib bar plot In this article, we will create a bar plot with error bars using Matplotlib. Error bar charts are a great way to represent the variability in your data. It can be applied to graphs to provide an additional layer of detailed information on the presented data.Approach:Import the required Python librar 3 min read Matplotlib.axes.Axes.scatter() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 4 min read How to add a legend to a scatter plot in Matplotlib ? Adding a legend to a scatter plot in Matplotlib means providing clear labels that describe what each group of points represents. For example, if your scatter plot shows two datasets, adding a legend will display labels for each dataset, helping viewers interpret the plot correctly. We will explore s 2 min read How to create a Scatter Plot with several colors in Matplotlib? Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc. In this article, we w 3 min read Like