How to merge three line plots into one that share one x-axis but have separate y-axes with matplotlib?

I am able to make the three graphs in matplotlib fine but not sure how to go about merging them into one whole graph sharing a single x-axis of months and a separate y-axes.

Here is the code I have for the three graphs that draw from three distinct csv files:

import pandas as pd 
import matplotlib.pyplot as plt
#import numpy as np

df = pd.read_csv('1541544819_et.csv', skiprows=4)

ax = df.plot(color="blue",kind='line', legend = False,figsize=(15,6))

ax.set_ylabel("Evapotranspiration (inches)")


ax.set_xticklabels(['Jan','Mar','May','Jul','Sep','Nov','Jan'], fontsize = 'large')

df = pd.read_csv('1541544819_rainfall.csv', skiprows=4)

ax2 = df.plot(color="orange",kind='line', legend = False,figsize=(15,6))

ax2.set_ylabel("Rainfall (inches)")


ax2.set_xticklabels(['Jan','Mar','May','Jul','Sep','Nov','Jan'], fontsize = 'large')



df = pd.read_csv('1541556002_water_level.csv', skiprows=4)

ax3 = df.plot(color="green",kind='line', legend = False,figsize=(15,6))

ax3.set_ylabel("Water Level (ft above NADV88)")


ax3.set_xticklabels(['Jan','Mar','May','Jul','Sep','Nov','Jan'], fontsize = 'large')



And that results in the following line plots:

enter image description here

Now I just need to merge them together stacked on top of each other. With the shared x-axis of months. Would appreciate any and all help.

Thank you

1 answer

  • answered 2018-11-08 00:04 Ryan Jarvis

    Have you tried eliminating the first two Statements to show show the plot?

    Then remove 2/3 of the ax, ax2, and ax3. They should all refer to the same x-axis?