matplotlib 点线动画
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 点线动画相关推荐
- python使用matplotlib可视化线图(line plot)、移除可视化结果的所有坐标轴信息(remove all axis in matplotlib graph)
python使用matplotlib可视化线图(line plot).移除可视化结果的所有坐标轴信息(remove all axis in matplotlib graph) 目录
- 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) 目 ...
- python使用matplotlib可视化线图(line plot)、在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot)
python使用matplotlib可视化线图(line plot).在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot) 目录
- python使用matplotlib可视化线图(line plot)、将可视化图像的图例(legend)放置在图像外部、底部区域
python使用matplotlib可视化线图(line plot).将可视化图像的图例(legend)放置在图像外部.底部区域(put legend outside and in bottom re ...
- python使用matplotlib可视化线图(line plot)、并自定义线条的粗细(线条的宽度、 line width in Matplotlib)
python使用matplotlib可视化线图(line plot).并自定义线条的粗细(线条的宽度. line width in Matplotlib) 目录
- 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) 目录
- python使用matplotlib可视化线图(line plot)、将可视化图像的图例(legend)放置在图像外部、右侧区域
python使用matplotlib可视化线图(line plot).将可视化图像的图例(legend)放置在图像外部.右侧区域(put legend outside and in right reg ...
- python使用matplotlib可视化线图(line plot)、自定义可视化图像的四个边框的色彩、可以分别设置矩形每一条边的色彩(change the axis color)
python使用matplotlib可视化线图(line plot).自定义可视化图像的四个边框的色彩.可以分别设置矩形每一条边的色彩(change the axis color of a plot ...
- 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) ...
最新文章
- 看了眼大厂程序员的工资单,我酸了!
- Arduino LiquidCrystal库函数中文对照
- 计算机网络第五章-运输层学习笔记
- python 系统托盘_使用 PySide 实现 Python 系统托盘图示
- 如何用jsp连接mysql_如何用jsp连接mysql数据库
- jboss项目导入idea_JBoss BPM Suite快速指南–将外部数据模型导入BPM项目
- 批处理写的关机小程序--bat
- 系统动力学建模工具_多体动力学:ANSYS Motion 2020R2
- 想测一下接口的并发数?手把手教你!
- Java做一个弹出表,至少有两个字段的简单的弹出窗体java表单
- 三合一收款二维码原理以及源码
- python右对齐输出乘法表_Python 第6讲 打印九九乘法表
- 利用计算机解决问题的一般过程是怎样的,计算机解决问题的一般过程1
- 【观察】并购魔方安全,联软科技再启新征程
- 【随笔】编程能力和程序员
- 大型网络中内部网关路由协议(IGP)的选择
- 2021年电工(初级)报名考试及电工(初级)考试内容
- 另一大短视频网址无水印下载,爱了吗?
- 虚拟机安装教程win7_虚拟机安装系统教程
- 【C语言训练】自由落体问题