pandas 散点图日期时间 [英] pandas scatter plotting datetime

查看:72
本文介绍了 pandas 散点图日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两列datetime.time的数据框.我想散布它们.理想情况下,我还希望轴显示时间.但是

I have a dataframe with two columns of datetime.time's. I'd like to scatter plot them. I'd also like the axes to display the times, ideally. But

df.plot(kind='scatter', x='T1', y='T2')

转储一堆内部绘图错误,这些错误以'T1'上的KeyError结尾.

dumps a bunch of internal plot errors ending with a KeyError on 'T1'.

或者,我尝试

plt.plot_date(x=df.loc[:,'T1'], y=df.loc[:,'T2'])
plt.show()

我得到了'Tkinter回调中的异常',以长长的堆栈抓取结束于

and I get 'Exception in Tkinter callback' with a long stack crawl ending in

return _from_ordinalf(x, tz)
  File "/usr/lib/python3/dist-packages/matplotlib/dates.py", line 224, in _from_ordinalf
microsecond, tzinfo=UTC).astimezone(tz)
TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'str'

有指针吗?

推荐答案

汤姆·奥格斯珀格(Tom Augspurger)建议,这不是一个真正的答案,而是一种解决方法,即您可以只使用工作线图类型并指定点而不是线:

Not a real answer but a workaround, as suggested by Tom Augspurger, is that you can just use the working line plot type and specify dots instead of lines:

df.plot(x='x', y='y', style=".")

这篇关于 pandas 散点图日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆