Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从datetimeindex开始的时间序列x轴日期_Python_Pandas_Time Series - Fatal编程技术网

Python 从datetimeindex开始的时间序列x轴日期

Python 从datetimeindex开始的时间序列x轴日期,python,pandas,time-series,Python,Pandas,Time Series,我有以下数据框,可以从中使用.groupby()为每个发送者生成图形: 这是我的密码: for key, grp in stack.groupby(['sender']): plt.plot(grp.index, grp['temp_3'].dropna(), label='%s %s' % ('Temperature', key)) 然而,当我将其应用于我的完整数据集时,在utctime中有多个日期,x轴仍然是一个时间-我希望它在本

我有以下数据框,可以从中使用.groupby()为每个发送者生成图形:

这是我的密码:

for key, grp in stack.groupby(['sender']):
    plt.plot(grp.index,
             grp['temp_3'].dropna(),
             label='%s %s' % ('Temperature', key))
然而,当我将其应用于我的完整数据集时,在utctime中有多个日期,x轴仍然是一个时间-我希望它在本例中显示日期

以下是完整数据集的示例:

                    sender  temp_3
utctime                                
2014-10-23 13:15:08           a    23.0
2014-10-24 16:09:13           b    24.1
2014-10-24 18:56:01           a    23.3
2014-10-24 21:42:42           a    23.0
2014-10-25 00:29:22           a    22.7
2014-10-25 03:16:02           c    23.1
2014-10-25 06:02:43           c    22.8
2014-10-25 08:49:23           c    23.7
2014-10-25 11:36:03           c    24.8
2014-10-25 14:22:43           c    25.7
2014-10-25 17:09:24           d    24.9
2014-10-25 19:56:05           b    24.6
2014-10-25 22:42:45           b    24.2
2014-10-26 01:29:26           e    22.7
2014-10-26 04:16:15           d    23.6
2014-10-26 07:02:56           e    22.4
2014-10-26 09:49:36           e    22.7
2014-10-26 12:36:16           e    22.2
2014-10-26 15:22:57           e    23.1
2014-10-26 18:09:46           d    23.8
2014-10-26 20:56:26           b    23.8
2014-10-26 23:43:07           e    22.7
我会张贴图片,但需要更多的代表


我已经尝试过将.to_julian_time和to_py_datetime转换为其他堆栈帖子。我也尝试过grp.index.date,但这仍然提供了x轴的时间,更糟糕的是,它丢失了细节。有什么想法吗?

在xaxis上设置格式应该可以做到:

plotaxis = plt.figure().gca()
plotaxis.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%d/%m/%y\n%H:%M'))
for key, grp in stack.groupby(['sender']):
plt.plot(grp.index,
         grp['temp_3'].dropna(),
         label='%s %s' % ('Temperature', key))

您是否尝试过plt.plot_date(…)?刚刚尝试过,但仍然存在相同的问题。如果您愿意尝试,我将添加一些具有不同日期的数据。这很有效。我在一个子地块上尝试了同样的技巧,我将每个发送者分割成一个单独的数据帧,而DateFormatter抛出了一个值错误。有什么建议吗?请看一下,也许您没有将其应用于子地块的轴(“演示代码中的ax”:fig,ax=plt.subplot()。
plotaxis = plt.figure().gca()
plotaxis.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%d/%m/%y\n%H:%M'))
for key, grp in stack.groupby(['sender']):
plt.plot(grp.index,
         grp['temp_3'].dropna(),
         label='%s %s' % ('Temperature', key))