首页 > 解决方案 > 动画matplotlib图,Y轴点排列不正确

问题描述

我目前正在用python编写一个脚本,该脚本用于测试DNS响应时间。我使用 matplotlib 以图形方式显示数据,但是随着图表的更新,这些点的排序方式不正确,我尝试了任何我能做的事情,但我无法弄清楚我的函数出了什么问题。我添加了动画功能和图形的图片。fyi FuncAnimation 使用生成器函数调用 animate ,每次迭代都会产生不同的 URL(在 google 和 facebook 之间),然后调用一个函数,该函数将新的 DNS 响应时间带到为 animate 函数提供值的字典中。

`def动画(网址):

    # The Y axis will represent the request/response time, while the
    plot_dict = master_dict[url]

    # x_val is a time string, format is "%H:%M:%S", y_val is a float.
    # in the array x_val turnin to numpy.string, y_val to a numpy.float64
    x_val = plot_dict[TIME]
    y_val = plot_dict[DNS]

    point = np.array([[x_val, y_val]])

    if 'google' in url:
        graph_list[0] = np.append(graph_list[0], point, axis=0)
        print graph_list[0].T
        x, y = graph_list[0].T
        return plt.plot(x, y, color='g')

    else:
        graph_list[1] = np.append(graph_list[1], point, axis=0)
        x, y = graph_list[1].T
        print graph_list[1].T
        return plt.plot(x, y, color='r')`

graph_list[0] 是 google 点的 2D numpy 数组,1是 facebook,每次我得到一个新点时,我都会将它添加到它的数组中

在此处输入图像描述

标签: pythonpython-2.7matplotlib

解决方案


推荐阅读