- 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
How to get a Gantt plot using matplotlib?
Gantt charts are widely used in project planning to show the project schedule. It's a type of bar chart that lists the tasks on the vertical axis and the time intervals on the horizontal axis. The width of the horizontal bars in the graph shows the duration of each activity.
To plot a Gantt chart in matplotlib, we can use the broken_barh() method.
Set the figure size and adjust the padding between and around the subplots.
Create a figure and a set of subplots.
Plot a horizontal sequence of rectangles.
Set the y and x limits of the axes.
To display the figure, use show() method.
import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Figure and set of subplots fig, ax = plt.subplots() # Horizontal sequence of rectangles ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='tab:blue') ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9), facecolors='tab:orange') # ylim and xlim of the axes ax.set_ylim(5, 35) ax.set_xlim(0, 200) # Show the plot plt.show()
It will produce the following output −
- Related Articles
- How to get a matplotlib Axes instance to plot to?
- How to plot a wav file using Matplotlib?
- How to plot collections.Counter histogram using Matplotlib?
- How to get all the legends from a plot in Matplotlib?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How to plot MFCC in Python using Matplotlib?
- How to plot events on time using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to plot 2d FEM results using matplotlib?
- How to plot a rectangle on a datetime axis using Matplotlib?
- Plot a bar using matplotlib using a dictionary
- How to a plot stem plot in Matplotlib Python?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to rotate the rectangle patch in a plot using Matplotlib?