Axes messed up trying to plot temporal series with matplotlib

Viewed 59

I've got an issue when trying to plot two temporal series with Matplotlib. The temporal series should share the same y-axis/scale since it's supposed to be a comparison on modeled and measured values. However, when plotting, it seems that the y and x scales are getting messed up:

Graph of one month of my data

Here is the code associated:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt

#import des données
Data=pd.read_csv('Filepath/Recept_41R001.csv', sep=';')
Data['Date']=pd.to_datetime(Data['Date'])
Data.sort_values(by='Date')
Data.set_index('Date', inplace=True)

Data01=Data['2018-01-01 00:00:00':'2018-01-31 23:00:00']

fig, ax=plt.subplots()
ax.plot(recept0101.index, recept0101['NO2_Mod'])
ax.plot(recept0101.index, recept0101['NO2_Mes'])
ax.set_xlabel('Time')
ax.set_ylabel('NO2 µg/m3')
ax.set_title('NO2 Modeled vs Mesured 01-2018')
ax.legend(['Modeled NO2','Mesured NO2'])
plt.show()
  • I've checked my data for the problematic time indexes and nothing seems to indicate a problem related to the data
  • The issue is the same regardless of the month I try to plot
  • Even excel recognises the data as float
  • The issue is still there when I try to set_ylim
  • I ran the code on IDLE (Python 3.9) and Visual Studio Code
1 Answers

Try to put

ax.plot(recept0101.index, recept0101['NO2_Mod'], linestyle='--')

ax.plot(recept0101.index, recept0101['NO2_Mes']),linestyle='--')
Related