Plot multiple time series DataFrame into a single plot - Pandas
Last Updated :
16 Jun, 2025
In this article, we’ll explore how to plot multiple time series from Pandas DataFrames into a single plot. When working with multiple time series, the most important factor is ensuring that their indexes (usually DateTime indexes) are aligned. We’ll cover two common scenarios:
- Time series with the same DateTime index
- Time series with different DateTime indexes
Time Series with the Same DateTime Index
When multiple time series share the same DateTime index, plotting them together is straightforward. Since their timestamps are already aligned, you can directly call .plot() on the DataFrame or individual columns to visualize them on a single graph.
Step 1: Importing Libraries
First, import the required libraries. pandas manages the data, while matplotlib.pyplot handles plotting. plt.style.use('default') sets a clean style and %matplotlib inline (for Jupyter) ensures plots render within the notebook.
Python
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('default')
%matplotlib inline # if using Jupyter Notebook
Step 2: Load Stock Data
We will be plotting open prices of three stocks Tesla, Ford, and general motors, You can download the data from here or yfinance library.
Tesla file:
Python
tesla = pd.read_csv('Tesla_Stock.csv', index_col='Date',parse_dates=True)
tesla.head(10)
Output

Ford_stock:
Python
ford = pd.read_csv('Ford_Stock.csv', index_col='Date', parse_dates=True)
ford.head(10)
Output

GM_Stock:
Python
gm = pd.read_csv('GM_Stock.csv', index_col='Date', parse_dates=True)
gm.head(10)
Output

Step 3: Now Plotting Open Prices of the Stocks
Since the time series share the same DateTime index, plotting is straightforward. You can directly call .plot() on the 'Open' column of each DataFrame to overlay them.
Python
plt.figure(figsize=(16, 8), dpi=150)
tesla['Open'].plot(label='Tesla', color='orange')
gm['Open'].plot(label='GM', color='blue')
ford['Open'].plot(label='Ford', color='green')
plt.title('Open Price Plot')
plt.xlabel('Years')
plt.ylabel('Open Price')
plt.legend()
plt.grid(True)
plt.show()
Output

Explanation: Since all three stocks have the same DateTime index, their data aligns perfectly across time. This allows us to directly call .plot() on each DataFrame’s 'Open' column without any preprocessing.
Plotting DataFrames with different DateTime Index
When time series DataFrames have different DateTime indexes, direct plotting can result in misaligned or incomplete data. To visualize them together accurately, you first need to align their indexes, typically by reindexing one DataFrame to match the other before plotting.
Step 1: Importing Libraries
First, import the required libraries. pandas manages the data, while matplotlib.pyplot handles plotting. plt.style.use('default') sets a clean style and %matplotlib inline (for Jupyter) ensures plots render within the notebook.
Python
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('default')
# If using Jupyter Notebook:
%matplotlib inline
Step 2: Importing Data
Here we load Apple (AAPL) and Microsoft (MSFT) stock price data, which have different date ranges.
Python
aapl = pd.read_csv('aapl.csv', index_col='Date', parse_dates=True)
aapl.head(10)
Output

msft file:
Python
msft = pd.read_csv('msft.csv', index_col='Date', parse_dates=True)
msft.head(10)
Output

Step 3: Align Index
Since their DateTime indexes do not completely overlap, we merge Microsoft’s prices into Apple’s DataFrame based on the Date index. This creates missing values where dates do not match.
Python
aapl["MSFT"] = msft["MSFT"] # Merge MSFT prices by Date
aapl.dropna(inplace=True) # Clean missing data
aapl.head(10)
Output

Step 4: Plot Aligned Time Series
Once the DateTime indexes of both time series are aligned and missing values handled, we can now plot them together. This visual representation allows for easy comparison of stock performance over time.
Python
plt.figure(figsize=(16, 8), dpi=150)
aapl.plot(label='aapl', color=['orange', 'green'])
# adding title
plt.title('Price Plot')
# adding label to x-axis
plt.xlabel('Years')
# adding legend.
plt.legend()
Output

Explanation: Apple and Microsoft data have different date ranges. When we merge them by index, gaps (NaNs) appear where one stock has data but the other does not. We handle this by using dropna() before plotting, ensuring clean, aligned visuals.
In some cases we can't afford to lose data, so we can also plot without removing missing values, plot for the same will look like:

Related articles
Similar Reads
Pandas - Plot multiple time series DataFrame into a single plot In this article, weâll explore how to plot multiple time series from Pandas DataFrames into a single plot. When working with multiple time series, the most important factor is ensuring that their indexes (usually DateTime indexes) are aligned. Weâll cover two common scenarios:Time series with the sa
3 min read
How to Plot Multiple Series from a Pandas DataFrame? In this article, we will discuss how to plot multiple series from a dataframe in pandas. Series is the range of the data  that include integer points we cab plot in pandas dataframe by using plot() function Syntax: matplotlib.pyplot(dataframe['column_name']) We can place n number of series and we ha
2 min read
How to Plot a Vertical Line on a Time Series Plot in Pandas When working with time series data in Pandas, it is often necessary to highlight specific points or events in the data. One effective way to do this is by plotting vertical lines on the time series plot. In this article, we will explore how to plot a vertical line on a time series plot in Pandas, co
3 min read
How to Plot a Dataframe using Pandas Pandas plotting is an interface to Matplotlib, that allows to generate high-quality plots directly from a DataFrame or Series. The .plot() method is the core function for plotting data in Pandas. Depending on the kind of plot we want to create, we can specify various parameters such as plot type (ki
8 min read
How to plot a Pandas Dataframe with Matplotlib? We have a Pandas DataFrame and now we want to visualize it using Matplotlib for data visualization to understand trends, patterns and relationships in the data. In this article we will explore different ways to plot a Pandas DataFrame using Matplotlib's various charts. Before we start, ensure you ha
2 min read
Time Series Plot or Line plot with Pandas Prerequisite: Create a Pandas DataFrame from Lists Pandas is an open-source library used for data manipulation and analysis in Python. It is a fast and powerful tool that offers data structures and operations to manipulate numerical tables and time series. Examples of these data manipulation operati
6 min read
Draw Multiple Time Series in Same Plot in R Time Series in R programming language is used to see how an object behaves over a period of time. In R, it can be easily done by the ts() function with some parameters. Time series takes the data vector and each data is connected with timestamp value as given by the user. Method 1: Using Basic R me
2 min read
Convert a series of date strings to a time series in Pandas Dataframe During the analysis of a dataset, oftentimes it happens that the dates are not represented in proper type and are rather present as simple strings which makes it difficult to process them and perform standard date-time operations on them. pandas.to_datetime() Function helps in converting a date str
3 min read
How to Plot Multiple Series/Lines in a Time Series Using Plotly in R? Plotly is a powerful and flexible graphing library that enables the creation of interactive plots in R. It is especially useful for visualizing time series data with multiple lines or series. In this article, we will cover how to plot multiple time series in a single plot using Plotly in R.Multiple
5 min read
How to Stack Multiple Pandas DataFrames? In this article, we will see how to stack Multiple Pandas Dataframe. Stacking means appending the dataframe rows to the second dataframe and so on. If there are 4 dataframes, then after stacking the result will be a single dataframe with an order of dataframe1,dataframe2,dataframe3,dataframe4. Panda
6 min read