- 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
Getting vertical gridlines to appear in line plot in matplotlib
Using plt.grid(axis="x") method, we can plot vertical gridlines.
Steps
Make a list of numbers.
Set the X-axis label using plt.xlabel() method.
Set the Y-axis label using plt.ylabel() method.
Toggle the gridlines, and optionally set the properties of the lines, using plt.grid() method.
To show the figure, use the plt.show() method, where the argument axis can be “x”, “y” or “both”.
Example
from matplotlib import pyplot as plt plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") plt.grid(axis="x") plt.show()
Output
- Related Articles
- Add minor gridlines to Matplotlib plot using Seaborn
- Legend with vertical line in matplotlib
- Line plot with arrows in Matplotlib
- How to independently set horizontal and vertical, major and minor gridlines of a plot?
- How to animate a line plot in Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- How to hide axes and gridlines in Matplotlib?
- How to plot a 3D continuous line in Matplotlib?
- How to plot a gradient color line in matplotlib?
- Getting empty tick labels before showing a plot in Matplotlib
- How to create a plot in R with gridlines using plot function?
- Adjusting gridlines and ticks in Matplotlib imshow
- How do you plot a vertical line on a time series plot in Pandas?
- How to plot a smooth line with matplotlib?
- How to plot a line graph from histogram data in Matplotlib?

Advertisements