安装

pip install celluloid

helloworld代码

from celluloid import Camera
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3Dfig = plt.figure()
ax4 = plt.axes(projection='3d')
camera = Camera(fig)
t = np.linspace(0, 5 * np.pi, 128, endpoint=False)
for i in t2:ax4.plot(t, np.cos(t/2 + i), np.sin(t/2 +i), color='b')camera.snap()animation = camera.animate()
animation.save('celluloid_example.gif', writer = 'imagemagick')

应用示例

import math
import random
import numpy as np
from celluloid import Camera
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from math import *def getlength(k):return np.exp(-20.0*(k-0.16))+6.0def getspeed(l):return np.sqrt(l*5.0)-2.0def recursive(control_points, T, B0=0, B1=0, dB0=0, dB1=0, ddB0=0, ddB1=0):if len(control_points) == 1:return control_points[0], -B0+(1-T)*dB0+B1+T*dB1, -2*dB0+(1-T)*ddB0+2*dB1+T*ddB1else:B0, dB0, ddB0 = recursive(control_points[0:-1], T)B1, dB1, ddB1 = recursive(control_points[1:], T)return (1-T)*B0 + T*B1 , -B0+(1-T)*dB0+B1+T*dB1, -2*dB0+(1-T)*ddB0+2*dB1+T*ddB1    roadcpx = [1., 1., 20., 40., 60]
roadcpy = [1., 20., 20., 1., 60]T = np.linspace(0, 1, 300)
x, dx, ddx = recursive(roadcpx, T)
y, dy, ddy = recursive(roadcpy, T)
theta = np.arctan2(dy, dx)
curvature = np.abs((dx*ddy-dy*ddx)/(dx**2+dy**2)**(3./2.))
def getArcLength(x, y):x0 = x[0]y0 = y[0]s = [0]for i in range(len(x)-1):x1 = x[i+1]y1 = y[i+1]dx = x1 - x0dy = y1 - y0ds = np.sqrt(dx*dx+dy*dy)s.append(ds+s[-1])x0 = x1y0 = y1return ss = getArcLength(x,y)def frenet_to_cartesian1D(rs, rx, ry, rtheta, s_condition, d_condition):if fabs(rs - s_condition[0])>= 1.0e-6:print("The reference point s and s_condition[0] don't match")cos_theta_r = cos(rtheta)sin_theta_r = sin(rtheta)x = rx - sin_theta_r * d_condition[0]y = ry + cos_theta_r * d_condition[0]    return x, yleft_bound = []
right_bound = []for i in range(300):rs = s[i]rx = x[i]ry = y[i]rtheta = theta[i]l_s_condition = np.array([rs])l_d_condition = np.array([1.5])lx, ly = frenet_to_cartesian1D(rs, rx, ry, rtheta, l_s_condition, l_d_condition)left_bound.append(np.array([lx, ly]))r_s_condition = np.array([rs])r_d_condition = np.array([-1.5])rx, ry = frenet_to_cartesian1D(rs, rx, ry, rtheta, r_s_condition, r_d_condition)   right_bound.append(np.array([rx, ry]))
left_bound = np.array(left_bound)
right_bound = np.array(right_bound)
fig = plt.figure(figsize=(8, 8),facecolor='lightyellow')
camera = Camera(fig)
for i in range(300): plt.plot(x, y, '--y')plt.plot(left_bound[:,0],left_bound[:,1], 'b')plt.plot(right_bound[:,0],right_bound[:,1], 'b')    plt.scatter(x[i], y[i], marker='o', color='g')length = round(getlength(curvature[i]), 2)speed = round(getspeed(length), 2)for j in range(i, 300):if s[j] > s[i]+length:plt.plot(x[i:j], y[i:j], 'r')breakplt.text(1, 56, 'trajectory length: '+str(length)+'m', fontsize=16)plt.text(1, 52, 'desired speed: '+str(speed)+'m/s', fontsize=16)plt.text(1, 60, 'lane curvature: '+str(curvature[i]), fontsize=16)#     plt.show()camera.snap()   animation = camera.animate()
animation.save('celluloid_example.gif', writer = 'imagemagick')

matplotlib+celluloid Camera可视化动态数据相关推荐

  1. Axure可视化动态数据图表6合1元件库

    Axure可视化动态数据图表6合1元件库 立即获取源文件 Axure可视化动态数据图表元件库包含了Echats图表组件 ,Gallery图表组件.AntV G2图表组件.AntV G6图表组件.Ant ...

  2. 实现Java Web开发的关于echarts可视化动态数据展示

    实现Java Web开发的关于可视化动态数据展示 echarts是一个实现动态数据展示最方便的图形化展示工具.它能够完成数据实时传递更新并且能够完成页面直观的展示.最开始时,echarts是由百度设计 ...

  3. Python之分享常用的五款动态数据可视化工具

    一.Tableau 世界知名的 BI 工具,以超强的可视化能力著称.它已经成为商业 BI 界的 TOP 选手,很多大型公司像阿里.谷歌都在使用,能快速搭建数据系统. 可以通过设置页面动画,来制作动态可 ...

  4. 聊聊我常用的5款动态数据可视化工具

    视频当道的时代,数据可视化自然也要动起来. 我常用的动态可视化工具主要有「Tableau.Echarts.Flourish.Python」这几个,另外加上地图可视化神器「kepler.gl」. 这五款 ...

  5. Python使用matplotlib函数subplot可视化多个不同颜色的折线图、在折线图上为每个数据点添加日期数据标签

    Python使用matplotlib函数subplot可视化多个不同颜色的折线图.在折线图上为每个数据点添加日期数据标签 目录

  6. Python使用matplotlib函数subplot可视化多个不同颜色的折线图、自定义数据点的形状、自定义折线图的颜色

    Python使用matplotlib函数subplot可视化多个不同颜色的折线图.自定义数据点的形状.自定义折线图的颜色 目录

  7. python使用matplotlib可视化间断条形图、使用broken_barh函数可视化间断条形图、可视化定性数据的相同指标在时间维度上的差异

    python使用matplotlib可视化间断条形图.使用broken_barh函数可视化间断条形图.可视化定性数据的相同指标在时间维度上的差异 目录 python使用matplotlib可视化间断条 ...

  8. python使用matplotlib可视化阶梯图、使用step函数可视化阶梯图、可视化时间序列数据的波动周期和规律

    python使用matplotlib可视化阶梯图.使用step函数可视化阶梯图.可视化时间序列数据的波动周期和规律 目录

  9. Python使用matplotlib可视化时间序列数据、并为时间序列曲线添加误差带、使用95%置信区间(Time Series Error Bands with confidence interval

    Python使用matplotlib可视化时间序列数据.并为时间序列曲线添加误差带.使用95%置信区间(Time Series with Error Bands with confidence int ...

最新文章

  1. Simple NHibernate Architecture[from]
  2. python list列表与array区别
  3. SMB(Server Message Block) Protocal Research
  4. 机器视觉:ransac算法详解
  5. Arduino 实现八段数码管显示练习
  6. mongodb 的安装使用步骤
  7. 【车间调度】基于matlab GUI遗传算法求解车间调度问题【含Matlab源码 049期】
  8. 用python自制一个简单的答题程序
  9. 易语言服务器卡密验证,想写一个关于辅助登录卡密的软件。 问题:易语言如何会做一个输入正确卡密才可以登入界面的...
  10. table导出excel php_php导出excel表格的方法分享(代码)
  11. CSP -- 运营商内容劫持(广告)的终结者
  12. MGV3000_YST_免费刷机固件包_原生设置无密码_支持外置USB无线网卡
  13. markdown数学公式(MathJax)
  14. 如何在iPhone上关闭“请勿打扰”
  15. 自编记单词小程序项目(自定义词库,多功能)C/C++语言实现
  16. 《奋斗》中徐志森的财商课
  17. 边云协同,边缘云更出彩
  18. 酷派大观4 8970 刷android 4.4,极速达百兆! 移动4G版酷派大观4网络体验
  19. NACOS2.1. 最新版本启动报错Caused by: java.sql.SQLSyntaxErrorException: Unknown column ‘encrypted_data_
  20. 如何从无到有设计一款字体

热门文章

  1. 【医学分割】u2net
  2. php 做app服务 开源,APP 与 PHP 的开源项目
  3. 石油大--2020年秋季组队训练赛第十二场---- L、The Assembly Code(模拟)
  4. JavaScript 开发者年度调查报告
  5. 网站 tooltip和title提示美化教程
  6. 在统计学中_统计学中的几个基本概念
  7. 第七章 论语与四书五经
  8. vue安装和开发环境搭建教程2021年
  9. 自动驾驶仿真工具之汇总
  10. html 表格 方向键,javascript实现的使用方向键控制光标在table单元格中切换