[PYTHON] When plotting time series data and getting a matplotlib Overflow Error

I'm a little addicted, so make a note

What you want to do

I want to plot sensor data timed in Unixtime with time on the horizontal axis and sensor data on the vertical axis.

As usual

import pandas as pd
import pandas.tseries.offsets as offsets

Data = pd.read_csv('data.csv')
Data['timestamp'] = pd.to_datetime(Data['timestamp'], unit="ms")
Data['timestamp'] += offsets.Hour(9)

Read the data with

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1) 
x = Data['timestamp']
y = Data['sensor']
ax.plot(x, y)

I said. .. ..

Appearance of error

matplotlib OverflowError: signed integer is greater than maximum

It seems that an OverflowError occurred because timestamp was a format that included up to milliseconds in UNIXTIME.

solution

http://stackoverflow.com/questions/11376080/plot-numpy-datetime64-with-matplotlib As written in.

x = Data['timestamp'].astype(datetime)

Like, it was drawn when the type was converted with .astype (datetime). Congratulations.

Recommended Posts

When plotting time series data and getting a matplotlib Overflow Error
Graph time series data in Python using pandas and matplotlib
About time series data and overfitting
Reading OpenFOAM time series data and sets data
Clogged when getting data from DB and making it a return value
Smoothing of time series and waveform data 3 methods (smoothing)
Format and display time series data with different scales and units with Python or Matplotlib
Time series plot / Matplotlib
A story about clustering time series data of foreign exchange
[Python] Plot time series data
polyfit error when installing matplotlib
Comparison of time series data predictions between SARIMA and Prophet models
<Pandas> How to handle time series data in a pivot table
Python: Time Series Analysis: Preprocessing Time Series Data
Versatile data plotting with pandas + matplotlib
Differentiation of time series data (discrete)
Time series analysis 3 Preprocessing of time series data
July, a certain, M5 ~ Kaggle beginner time series data competition failure story ~
Plot CSV of time series data with unixtime value in Python (matplotlib)
Plot multiple maps and data at the same time with Python's matplotlib