- 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 plot a stacked event duration using Python Pandas?
To plot a stacked event duration using Python Pandas, we can take the following steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a dataframe with lists of xmin and its corresponding xmax.
- Use hlines() method to plot a stacked event duration.
- To display the figure, use show() method.
Example
import pandas as pd from datetime import datetime as dt from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(xmin=[dt.strptime('1994-07-19', '%Y-%m-%d'), dt.strptime('2006-03-16', '%Y-%m-%d'), dt.strptime('1980-10-31', '%Y-%m-%d'), dt.strptime('1981-06-11', '%Y-%m-%d'), dt.strptime('2006-06-28', '%Y-%m-%d')], xmax=[dt.strptime('1998-06-30', '%Y-%m-%d'), dt.strptime('2007-01-24', '%Y-%m-%d'), dt.strptime('2007-07-31', '%Y-%m-%d'), dt.strptime('1990-08-01', '%Y-%m-%d'), dt.strptime('2007-01-24', '%Y-%m-%d')] )) plt.hlines(df.index, df.xmin, df.xmax, lw=5, colors='red') plt.show()
Output
- Related Articles
- Python Pandas - Plot a Stacked Horizontal Bar Chart
- How to create stacked plot with density using ggplot2 in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- How to plot CSV data using Matplotlib and Pandas in Python?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How to display stacked bar chart using matplotlib in Python?
- Python - How to plot a Pandas DataFrame in a Bar Graph
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- How to plot certain rows of a Pandas dataframe using Matplotlib?
- How to create a stacked area chart using JavaFX?
- How to create a stacked bar chart using JavaFX?
- How to plot two columns of a Pandas data frame using points?
- How to plot arbitrary markers on a Pandas data series using Matplotlib?
- How to plot an area in a Pandas dataframe in Matplotlib Python?

Advertisements