- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 plot overlapping lines in Matplotlib?
To plot overlapping lines in matplotlib, we can use variable overlapping that basically sets the opacity or alpha value in the plot.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Initialize a variable overlapping to set the alpha value of the line.
- Plot line1 and line2 with red and green colors, respectively, with the same alpha value.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True overlapping = 0.150 line1 = plt.plot([1, 3, 5, 2, 5, 3, 1], c='red', alpha=overlapping, lw=5) line2 = plt.plot([7, 2, 5, 7, 5, 2, 7], c='green', alpha=overlapping, lw=5) plt.show()
Output
- Related Articles
- How to remove lines in a Matplotlib plot?
- How to draw axis lines inside a plot in Matplotlib?
- How to plot the lines first and points last in Matplotlib?
- How to name different lines in the same plot of Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- How to plot two dotted lines and set marker using Matplotlib?
- How to avoid overlapping error bars in matplotlib?
- Matplotlib Plot Lines with Colors through Colormap
- Best way to plot an angle between two lines in Matplotlib
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to hide lines in Matplotlib?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- How to get multiple overlapping plots with independent scaling in Matplotlib?
- Draw axis lines or the origin for Matplotlib contour plot.
- How to a plot stem plot in Matplotlib Python?

Advertisements