Matplotlib ignoring timezone

前端 未结 2 1409
北恋
北恋 2021-02-09 13:04

The following plot

import matplotlib
f= plt.figure(figsize=(12,4))
ax = f.add_subplot(111)
df.set_index(\'timestamp\')[\'values\'].plot(ax=ax)
ax.xaxis.set_majo         


        
2条回答
  •  名媛妹妹
    2021-02-09 14:00

    I think you can have the desired functionality by setting the timezone in rcParams:

    import matplotlib
    matplotlib.rcParams['timezone'] = 'US/Eastern'
    

    The formatter is timezone aware and will convert the timestamp to your rcParams timezone (which is probably at UTC), while if you don't format it, it will just take the timestamp and ignore the timezone. If I understand correctly.

    More reading:

    • Matplotlib dates
    • A related answer

提交回复
热议问题