python - 动画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,每次我得到一个新点时,我都会将它添加到它的数组中
解决方案
推荐阅读
- ios - 如何在 Objective-C 和 Swift 中实现“didSelectButtonInCellAtIndexPath:”?
- postgresql - openshift 上的 keycloak 和 postgresql
- javascript - 如何制作基于 Web 的拖放表单构建器?
- ios - 表达式类型不明确,没有更多上下文错误
- json - 使用 json-server 模拟搜索过滤器
- vba - 无法使用以下方法在相关列中写入结果
- python - 将空列表替换为诸如“a”之类的字符
- javascript - 页面上传输的 Javascript 数据量
- javascript - 在下拉列表中实现按日期过滤功能
- javascript - 从其他数组jquery中删除多个数组