- 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
Controlling the width of bars in Matplotlib with per-month data
To control the width of bars in matplotlib with per-month data, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots
- Make a list of dates, x and y, using numpy.
- Plot the bar with x and y data points, with per-month data.
- To display the figure, use show() method.
Example
import numpy as np import datetime from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [datetime.datetime(2021, 1, 1, 0, 0), datetime.datetime(2021, 2, 1, 0, 0), datetime.datetime(2021, 3, 1, 0, 0), ] y = np.cos(np.arange(3) * 2) plt.bar(x, y, width=[(x[j+1]-x[j]).days for j in range(len(x)-1)] + [30]) plt.show()
Output
- Related Articles
- The following data relates to the expenditure of the families ( A ) and ( B ) per month.
- Python matplotlib multiple bars
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to decrease the width of bars for plotly bar chart in R?
- The fees of a student increases from Rs.1000 per month to Rs. 1200 per month. Find the percentage increase.
- Transparent error bars without affecting the markers in Matplotlib
- Plot 3D bars without axes in Matplotlib
- How to determine the order of bars in a matplotlib bar chart?
- Specifying the line width of the legend frame in Matplotlib
- How to avoid overlapping error bars in matplotlib?
- Adjust the width of box in boxplot in Python Matplotlib
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How to add percentages on top of bars in Seaborn using Matplotlib?
- How do I get all the bars in a Matplotlib bar chart?
- The average salary of 19 workers in a factory is ₹ 12,000 per month. If the salary of the manager is ₹ 42,000 per month, find the average monthly salary paid to all the employees.

Advertisements