- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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
Fill between two vertical lines in matplotlib
To fill color between two vertical lines, use the following steps −
Using plt.subplots() method, create a figure and a set of subplots. This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.
To draw two vertical lines, initialize x = 3 and x = 5.
Using the created ax, axvspan would help to add vertical span(rectangle) across the axes.
This rectangle spans from xmin to xmax horizontally, and, by default, the whole Y-axis vertically.
To show the figure, use the plt.show() method.
import matplotlib.pyplot as plt fig, ax = plt.subplots() line1 = 3 # vertical x = 3 line2 = 5 # vertical x = 5 ax.axvspan(line1, line2, alpha=.5, color='green') plt.show()
- Related Articles
- Drawing lines between two plots in Matplotlib
- Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib
- Best way to plot an angle between two lines in Matplotlib
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- How to create two vertical lines on a plot with shaded area in-between using R?
- Vertical Histogram in Python and Matplotlib
- Legend with vertical line in matplotlib
- Barchart with vertical labels in Python/Matplotlib
- Manipulation on vertical space in Matplotlib subplots
- How to plot two dotted lines and set marker using Matplotlib?
- How to hide lines in Matplotlib?
- How to plot overlapping lines in Matplotlib?
- How to create a circle with vertical lines in R?
- Set a border between two lines with CSS
- Find the area between two curves plotted in Matplotlib