- 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
Define the size of a grid on a plot using Matplotlib
To define the size of a grid on a plot, we can take the following steps −
Create a new figure or activate an existing figure using figure() method.
Add an axes to the figure as a part of a subplot arrangement.
Plot a curve with an input list.
Make x and y margins 0.
To set X-grids, we can pass input ticks points.
To lay out the grid lines in current line style, use grid(True) method.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) ax.plot([0, 2, 5, 8, 10, 1, 3, 14], 'ro-') ax.margins(x=0, y=0) grid_points = [1., 2., 3., 10.] ax.xaxis.set_ticks(grid_points) ax.grid(True) plt.show()
Output
- Related Articles
- How do I show logarithmically spaced grid lines at all ticks on a log-log plot using Matplotlib?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- How to plot a rectangle on a datetime axis using Matplotlib?
- Plot a polar color wheel based on a colormap using Python/Matplotlib
- Plot a bar using matplotlib using a dictionary
- How to place customized legend symbols on a plot using Matplotlib?
- How to change xticks font size in a matplotlib plot?
- Controlling the alpha value on a 3D scatter plot using Python and Matplotlib
- Setting the limits on a colorbar of a contour plot in Matplotlib
- How to increase the font size of the legend in my Seaborn plot using Matplotlib?
- How to plot additional points on the top of a scatter plot in Matplotlib?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
- How to plot arbitrary markers on a Pandas data series using Matplotlib?
- How to plot events on time using Matplotlib?

Advertisements