Python 大熊猫标记时间序列的绘制

Python 大熊猫标记时间序列的绘制,python,matplotlib,pandas,Python,Matplotlib,Pandas,我想在同一张图上绘制几个时间序列。在水平面上,我想要一个点,ts说发生了什么事。垂直轴是系列的标签。所以所有的A点都在相同的y值上,标记为A。B点在不同的y值上,标记为B。等等 我是一个熊猫新手,但我不知道如何做到这一点,除非通过一点编程来制作散点图。看来我做错了 这里有一个例子。考虑这个数据,标签是时间: cows 1416339311 cats 1416339312 dogs 1416339313 dogs 1416339314 cows 1416339330 cats 1416339339

我想在同一张图上绘制几个时间序列。在水平面上,我想要一个点,ts说发生了什么事。垂直轴是系列的标签。所以所有的A点都在相同的y值上,标记为A。B点在不同的y值上,标记为B。等等

我是一个熊猫新手,但我不知道如何做到这一点,除非通过一点编程来制作散点图。看来我做错了

这里有一个例子。考虑这个数据,标签是时间:

cows 1416339311
cats 1416339312
dogs 1416339313
dogs 1416339314
cows 1416339330
cats 1416339339
cats 1416339340
那么,情节是这样的:

一个更现实的情节应该是这样的,它向我们展示了牛很早就活跃,猫很早很晚,狗大多在中间时间:


在JD Long的上述帮助下,这是我最后编写的函数:

def plot_times_by_club(df, live, zero):
"""Plot the times for each club.

If zero is True, then set first x-tick at 0 seconds (beginning of race)."""
times = df.loc[:, ['time', 'club']]
clubs = times.club.unique()
fig, ax = plt.subplots(len(clubs), sharex=True, sharey=True)
for index, club in enumerate(clubs):
    these_times = times[times.club == club]
    ax[index].plot(these_times.time.as_matrix(), np.ones(len(these_times)), 'o')
    ax[index].set_ylabel(club, rotation='horizontal', labelpad=30)
    ax[index].set_yticks([])
    ax[index].set_ybound(0.5, 1.5)
    ax[index].set_position([0.1, 0.1, 8.0, 1.0])
    ax[index].set_yticks([])
ax[0].set_title('Temps vu par club')
min_tick = ax[0].get_xticks().min()
if zero:
    min_tick = 0.0
    ax[0].set_xbound(lower=0.0)
max_tick = ax[0].get_xticks().max()
ax[0].set_xticks(np.linspace(min_tick, max_tick, 6))
fig.subplots_adjust(hspace=0)
render_plot(8, 6, live, 'jn8-club-{0}.png'.format(zero))

def render_plot(xdim, ydim, live, filename):
"""Display or save the plot image.

If live is True, then display in a window.
If live is False, save to the named file."""
if live:
    plt.show()
else:
    gc = plt.gcf()
    gc.set_size_inches(xdim, ydim)
    gc.savefig(filename, dpi=100)

您能给出一些示例数据,然后给出您想要的输出示例吗?做一个基本的绘图,然后甚至用手在上面画出你想添加的附加位。很难接受你的问题并想象你在追求什么。JD Long-好主意,Donew x轴是什么?是时间索引还是数据中的值?因此,您的示例中的数据不会捕获到绘图中?想想你桌子上的[1,2,3,4,4.75,5,6]。。。现在我明白了