Introduction
In this article, I would like to show how to plot two different Y axes on the same X-axis with different left and right scales. For this example, I have taken data on India’s yearly Ratio of External Debt to GDP from 1991 through 2019 and BSE Sensex closing rates for 1991 through 2019. Let’s see if there is a correlation between this data.
Import libraries
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
Get data in Python from Excel. Excel sheet and the ipynb file for this sample data is attached along with this article for anyone to download.
- debt = pd.read_excel("India Debt and Sensex.xlsx", sheet_name="Debt Data",
- skiprows=2,index_col=0)
- sensex = pd.read_excel("India Debt and Sensex.xlsx", sheet_name="Sensex Data",
- index_col=0)
Here Year column is made as index. After getting in the data, you will realize there is some gap in data on external debt. A few intermittent years' data is not available. For that, we can check the shape of both data.
- data1 = debt.iloc[:,1]
- print(data1.shape)
- data2 = sensex["Close"]
- print(data2.shape)


John WilsonPosted Apr 23, 2020, 2:26 PM
The purpose of this article is not clear