- 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 draw grid lines behind Matplotlib bar graph?
To draw grid lines behind matplotlib bar graph, we can take the following Steps −
Make a list of numbers, i.e., data.
Make a bar using the bar() method, by passing data, color='red' and alpha = 0.5. The alpha blending value should be between 0 (transparent) and 1 (opaque).
To configure the grid lines, use the grid() method, with color='yellow', linewidth=1, axis='both' and alpha=0.5.
To display the figure, show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [3, 5, 9, 15, 12] plt.bar(range(len(data)), data, color='red', alpha=0.5) plt.grid(color='yellow', linewidth=1, axis='both', alpha=0.5) plt.show()
Output
- Related Articles
- How to remove grid lines from an image in Python Matplotlib?
- How to draw more type of lines in Matplotlib?
- How to give a Pandas/Matplotlib bar graph custom colors?
- How to draw axis lines inside a plot in Matplotlib?
- Draw magnetic field lines around a bar magnet.
- How to plot a bar graph in Matplotlib from a Pandas series?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- Draw a bar graph to represent the following information:YEAR2004200520062007200820092010NO. OF CARS120145165195225240275
- Draw a bar graph for the followinSTUDENT MARK SHEET
- Indicating the statistically significant difference in bar graph (Matplotlib)
- How to show a bar and line graph on the same plot in Matplotlib?
- How to draw a rectangle over a specific region in a Matplotlib graph?
- How to draw parallel lines?
- CSS Grid Lines
- Draw a diagram to show the magnetic field lines around a bar magnet.

Advertisements