- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 skip empty dates (weekends) in a financial Matplotlib Python graph?

To skip weekends in a financial graph in matplotlib, we can iterate the time in dataframe and skip the plot if weekday is 5 or 6.

## Steps

Set the figure size and adjust the padding between and around the subplots.

Create a dataframe with

**keys**time.Iterate zipped index and time of a date frame.

If iterated timestamp is having weekday 5 or 6, don't plot them.

Other than 5 or 6 weekday, plot the points.

Set the current tick locations of Y-axis.

Lay out a plot with grid lines.

To display the figure, use

**show()**method.

## Example

import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(time=list(pd.date_range(start="2021-01-01", end="2021-01-15")))) for i, t in zip(df.index, df.time): if t.weekday() in (5, 6): pass else: plt.plot(i, t, marker="*", ms=10) plt.yticks(df.time) plt.grid(True) plt.show()

## Output

- Related Articles
- How to create an empty Figure with Matplotlib in Python?
- How to Add Markers to a Graph Plot in Matplotlib with Python?
- How to plot a high resolution graph in Matplotlib?
- How to make a grouped boxplot graph in matplotlib?
- Plotting a cumulative graph of Python datetimes in Matplotlib
- How to add Matplotlib graph in Kivy?
- How to manage image resolution of a graph in Matplotlib
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How can matplotlib be used to plot 3 different datasets on a single graph in Python?
- How to plot a line graph from histogram data in Matplotlib?
- How to shift a graph along the X-axis in matplotlib?
- How to plot a bar graph in Matplotlib from a Pandas series?
- How to Order by date in MySQL but place empty dates in the end?
- Python Pandas – How to skip initial space from a DataFrame
- How to plot a graph in Python?

Advertisements