- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to avoid overlapping error bars in matplotlib?
To avoid overlapping error bars in matplotlib, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a list of names.
Get the data points for y1 and y2, and errors ye1, ye2.
Create a figure and a set of subplots.
Create a mutable 2D affine transformation, trans1 and trans2.
Plot y versus x as lines and/or markers with attached errorbars.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = ['Jack', 'James', 'Tom', 'Garry'] y1, y2 = np.random.randn(2, len(x)) ye1, ye2 = np.random.rand(2, len(x))*4+0.3 fig, ax = plt.subplots() trans1 = Affine2D().translate(-0.1, 0.0) + ax.transData trans2 = Affine2D().translate(0.1, 0.0) + ax.transData er1 = ax.errorbar(x, y1, yerr=ye1, marker="*", linestyle="none", transform=trans1) er2 = ax.errorbar(x, y2, yerr=ye2, marker="o", linestyle="none", transform=trans2) plt.show()
Output
It will produce the following output −
- Related Articles
- How to avoid overlapping of labels & autopct in a Matplotlib pie chart?
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?
- Transparent error bars without affecting the markers in Matplotlib
- How to plot overlapping lines in Matplotlib?
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)
- How to add and remove error bars in Excel?
- How to get multiple overlapping plots with independent scaling in Matplotlib?
- How to remove gaps between bars in Matplotlib bar chart?
- How To Annotate Bars in Bar Plot with Matplotlib in Python?
- How to avoid #ref error while deleting the rows in Excel?
- Python matplotlib multiple bars
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to sort bars in a bar plot in ascending order (Matplotlib)?
- How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?
- How can I add textures to my bars and wedges in Matplotlib?

Advertisements