matplotlib 点线动画

  • 作者的Github [ 主写(Web Development(HTML, PHP, CSS, JS), node.js, Ruby(Sketchup API), Python(Tkinter, Django, Matplotlib), Batch Script) ]
  • Github开源群,代码交流,分享有意思的项目
  • 若二维码过期,请扫描群主二维码,或者添加微信号 mark60213


Matplotlib 一点一线动画


  • Python 3.7.3
  • Matplotlib 3.1.1

如题,直接上代码了

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimationdef vector_animate(fig, left_x, left_y, right_x, right_y, color, interval, line=True, dot=True):def update(frame):if line:if frame != 0:plt.plot([x_res[frame - 1], x_res[frame]], [y_res[frame - 1], y_res[frame]], color=color)p.set_data(x_res[frame], y_res[frame])return p,def init():p.set_data(x_res[0], y_res[0])return p,x_res = []y_res = []for i in range(len(left_x)):x_res.append(left_x[i] + ((right_x[i] - left_x[i]) * float(i / (len(left_x) - 1))))y_res.append(left_y[i] + ((right_y[i] - left_y[i]) * float(i / (len(left_x) - 1))))if dot:p, = plt.plot(x_res[0], y_res[0], "o", color=color)else:p, = plt.plot(x_res[0], y_res[0], color=color)return FuncAnimation(fig=fig, func=update, init_func=init, frames=[x for x in range(len(left_x))],interval=interval, repeat=False)fig = plt.figure()
x_on_left = [0, 0, 0, 0, 0, 0] # 左点x
y_on_left = [0, 2, 4, 6, 8, 10] # 左点y
x_on_right = [10, 10, 10, 10, 10, 10] # 右点x
y_on_right = [0, 2, 4, 6, 8, 10] # 右点yplt.xlim(0, 10)
plt.ylim(0, 10)va = vector_animate(fig, x_on_left, y_on_left, x_on_right, y_on_right, "k", 400)
# 400 是速度设置,数值越大,速度越慢plt.show()

做出来的是一点一线运动
vector_animate的参数line和dot是boolean值,若将dot设置为False, 只显示线;若将line设置为False, 只显示点。
注意下xlim和ylim必须设置,不然动画是乱的

matplotlib 点线动画相关推荐

  1. python使用matplotlib可视化线图(line plot)、移除可视化结果的所有坐标轴信息(remove all axis in matplotlib graph)

    python使用matplotlib可视化线图(line plot).移除可视化结果的所有坐标轴信息(remove all axis in matplotlib graph) 目录

  2. python使用matplotlib可视化线图(line plot)、设置X轴坐标的下限和上限数值(setting the lower and upper bound of the x axis)

    python使用matplotlib可视化线图(line plot).设置X轴坐标的下限和上限数值(setting the lower and upper bound of the x axis) 目 ...

  3. python使用matplotlib可视化线图(line plot)、在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot)

    python使用matplotlib可视化线图(line plot).在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot) 目录

  4. python使用matplotlib可视化线图(line plot)、将可视化图像的图例(legend)放置在图像外部、底部区域

    python使用matplotlib可视化线图(line plot).将可视化图像的图例(legend)放置在图像外部.底部区域(put legend outside and in bottom re ...

  5. python使用matplotlib可视化线图(line plot)、并自定义线条的粗细(线条的宽度、 line width in Matplotlib)

    python使用matplotlib可视化线图(line plot).并自定义线条的粗细(线条的宽度. line width in Matplotlib) 目录

  6. python使用matplotlib可视化线图(line plot)、使用invert_yaxis函数将Y轴坐标反序(invert the y axis in matplotlib)

    python使用matplotlib可视化线图(line plot).使用invert_yaxis函数将Y轴坐标反序(invert the y axis in matplotlib) 目录

  7. python使用matplotlib可视化线图(line plot)、将可视化图像的图例(legend)放置在图像外部、右侧区域

    python使用matplotlib可视化线图(line plot).将可视化图像的图例(legend)放置在图像外部.右侧区域(put legend outside and in right reg ...

  8. python使用matplotlib可视化线图(line plot)、自定义可视化图像的四个边框的色彩、可以分别设置矩形每一条边的色彩(change the axis color)

    python使用matplotlib可视化线图(line plot).自定义可视化图像的四个边框的色彩.可以分别设置矩形每一条边的色彩(change the axis color of a plot ...

  9. python使用matplotlib可视化线图(line plot)、并自定义设置可视化图像线条的类型(specify the line style of a plot in matplotlib)

    python使用matplotlib可视化线图(line plot).并自定义设置可视化图像线条的类型(specify the line style of a plot in matplotlib) ...

最新文章

  1. 看了眼大厂程序员的工资单,我酸了!
  2. Arduino LiquidCrystal库函数中文对照
  3. 计算机网络第五章-运输层学习笔记
  4. python 系统托盘_使用 PySide 实现 Python 系统托盘图示
  5. 如何用jsp连接mysql_如何用jsp连接mysql数据库
  6. jboss项目导入idea_JBoss BPM Suite快速指南–将外部数据模型导入BPM项目
  7. 批处理写的关机小程序--bat
  8. 系统动力学建模工具_多体动力学:ANSYS Motion 2020R2
  9. 想测一下接口的并发数?手把手教你!
  10. Java做一个弹出表,至少有两个字段的简单的弹出窗体java表单
  11. 三合一收款二维码原理以及源码
  12. python右对齐输出乘法表_Python 第6讲 打印九九乘法表
  13. 利用计算机解决问题的一般过程是怎样的,计算机解决问题的一般过程1
  14. 【观察】并购魔方安全,联软科技再启新征程
  15. 【随笔】编程能力和程序员
  16. 大型网络中内部网关路由协议(IGP)的选择
  17. 2021年电工(初级)报名考试及电工(初级)考试内容
  18. 另一大短视频网址无水印下载,爱了吗?
  19. 虚拟机安装教程win7_虚拟机安装系统教程
  20. 【C语言训练】自由落体问题

热门文章

  1. Excel图表宝典(英文版) - 图表初步
  2. 【ML】 第四章 训练模型
  3. java中算术异常值_依据拉依达准则来剔除异常值程序
  4. 在EXCEL2010中添加打印水印
  5. 语音论文:用于端到端语音识别的简化完全量化的Transformer模型
  6. java 反射 获取 实例_java通过类反射获取某个类的所有信息--代码实例
  7. Windows静默安装
  8. linux命令v---vi
  9. 性能测试---如何确定最大并发用户数
  10. 阿里跟腾讯又㕛叒打起来了,这次是在东南亚