fig, (ax1,ax2) = plt.subplots(1,2, figsize=(8,5), sharex = True)
- это одна строка и два столбца, поэтому sharex не имеет смысла.
И ax1, ax2 - это вспомогательные участки, поэтому их повторная инициализация не требуется
import pandas as pd
import matplotlib.pyplot as plt
data_loc = 'D:\CSVs\Water_Consumption_In_The_New_York_City.csv'
df = pd.read_csv(data_loc, parse_dates=True)
#editing the population data to be per million
df['New York City Population'] = df['New York City Population']/1000000
fig, (ax1,ax2) = plt.subplots(2, 1, figsize=(8,5), sharex = True)
ax1.plot(df['Year'], df['NYC Consumption(Million gallons per day)'])
ax1.legend(['Water Consumption (Million Gallons per Day)'])
ax2.plot(df['Year'], df['New York City Population'], color='red')
ax2.legend(['Population (In Millions)'])
plt.xlabel('Year')
plt.suptitle('NYC Water Consumption Data', size = 15)
plt.show()