3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

時系列データをプロットしてmatplotlib OverflowErrorがでたとき

Last updated at Posted at 2017-02-16

ちょっとはまったのでメモ

#したいこと
Unixtimeで時刻付されたセンサデータを横軸時刻,縦軸センサデータでプロットしたい.

いつも通り

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)

でデータを読み込み,

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

としたところ...

#エラーの出現

matplotlib OverflowError: signed integer is greater than maximum

timestampが,UNIXTIMEにミリ秒まで含んだ形式だったので,OverflowErrorとなったようです.

#解決策

http://stackoverflow.com/questions/11376080/plot-numpy-datetime64-with-matplotlib
に書いてあるとおりです.

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

のように,.astype(datetime)で型を変換すると描画されました.めでたしめでたし.

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?