Python Matplotlib.plot Update image Questions
1. 最近在测试一款设备,采集了一些设备后需要一帧一帧显示图像,经常使用Python,所以选用了Matplotlib进行图像操作
数据结构: timesatamp polar_distance horizontal_angle refelectivity_intensity,所有数据类型都是 float,储存在文件内并且以空格分隔
import math
import matplotlib.pyplot as plt #read data from file
def LoadData(filename):
inFile = open(filename, 'r') #declare two empty list,to save data
inten = []
polar_dist = []
hori_angle = [] for line in inFile:
splitline = line.split(" ")
polar_dist.append(splitline[1])
hori_angle.append(splitline[2])
inten.append(splitline[3])
inFile.close() #mapping to float
polar_dist = list(map(float,polar_dist))
hori_angle = list(map(float,hori_angle))
inten = list(map(float,inten)) return(polar_dist, hori_angle,inten)
2. 显示极坐标图像
def GenerateImageFromData(polar,angle,inten):
d2r = math.pi/180
for i in range(len(polar)):
angle[i] = d2r*(angle[i] +180)
plt.ion()
#inreactive code
ax = plt.subplot(111, projection='polar')
for i in range(100):
c = ax.scatter(angle[i*167 :(i+1)*167], polar[i*167 :(i+1)*167], s = 10)
plt.show()
plt.pause(1)
3. 调用函数
if __name__=="__main__":
(polar,angle,inten) = LoadData("CloudData.txt")
GenerateImageFromData(polar,angle,inten)
当绘图语句中加入pl.ion()时,表示打开了交互模式。此时python解释器解释完所有命令后,给你出张图,但不会结束会话,而是等着你跟他交流交流。如果你继续往代码中加入语句,run之后,你会实时看到图形的改变。当绘图语句中加入pl.ioff()时或不添加pl.ion()时,表示打关了交互模式。
4. 另外一个example
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 16 21:26:17 2017 @author: XX
""" import matplotlib.pylab as plt
import numpy as np
import math #clear images
plt.close() fig = plt.figure()
ax = fig.add_subplot(111) #ratio of x and y axis
ax.axis("equal") #enable grid of image
ax.grid(True) #activate inreactivate mode
plt.ion() init_x = 0.0
init_y = 3.5
init_angle = 45
init_wind_speed = 3 print("inreactive mode beginning")
try:
for t in range(50):
x = init_x + init_wind_speed*math.sin(math.pi/180*init_angle)*t
y = init_y + init_wind_speed*math.cos(init_angle*math.pi/180)*t
ax.scatter(x,y,c='r', s =5, marker ='^')
plt.pause(0.2)
except Exception as err:
print(err)
Python Matplotlib.plot Update image Questions的更多相关文章
- python matplotlib plot 数据中的中文无法正常显示的解决办法
转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...
- python matplotlib.plot画图显示中文乱码的问题
在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...
- 使用Python matplotlib做动态曲线
今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...
- python matplotlib 中文显示乱码设置
python matplotlib 中文显示乱码设置 原因:是matplotlib库中没有中文字体.1 解决方案:1.进入C:\Anaconda64\Lib\site-packages\matplot ...
- Python - matplotlib 数据可视化
在许多实际问题中,经常要对给出的数据进行可视化,便于观察. 今天专门针对Python中的数据可视化模块--matplotlib这块内容系统的整理,方便查找使用. 本文来自于对<利用python进 ...
- 转:使用 python Matplotlib 库 绘图 及 相关问题
使用 python Matplotlib 库绘图 转:http://blog.csdn.net/daniel_ustc/article/details/9714163 Matplotlib ...
- 安装python Matplotlib 库
转:使用 python Matplotlib 库 绘图 及 相关问题 使用 python Matplotlib 库绘图 转:http://blog.csdn.net/daniel_ustc ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
随机推荐
- Windows下载安装虚拟机和CentOS7
1,想要在Windows系统中安装linux系统,首先需要安装一个虚拟机VMware VMware 12下载地址:https://my.vmware.com/cn/web/vmware/info/sl ...
- 13-THREE.JS 点光源
<!DOCTYPE html> <html> <head> <title>Example 03.02 - point Light</title&g ...
- MAMP mac下启动Mysql
MAMP mac下启动Mysql /Applications/MAMP/Library/bin/mysql -u root -p 初始密码 root:
- Nhibernate系列学习之(四) 数据操作
数据操作,在这里主要介绍INSERT.UPDATE.DELETE.我们在使用NHibernate的时候,如果只是查询数据,不需要改变数据库的值,那么是不需要提交或者回滚到数据库的. 一.INSERT ...
- 让camera实现类似cs第一人称视角旋转和位移
直接把这个脚本挂在摄像机上就可: using System.Collections; using System.Collections.Generic; using UnityEngine; /* * ...
- HDU2665Kth number (主席树+离散)
Give you a sequence and ask you the kth big number of a inteval. InputThe first line is the number o ...
- 一道SQL的面试题之联想
一道SQL的面试题之联想 本人工作在一家小型的民营企业,主要从事业务系统的日常维护,二次开发,菜鸟一枚.周五经理准备面试两个开发人员,据简历,都还比较不错,让经理产生了想法,于是准备了一套面试题目,给 ...
- Windbg内核调试之二: 常用命令
运用Windbg进行内核调试, 熟练的运用命令行是必不可少的技能. 但是面对众多繁琐的命令, 实在是不可能全部的了解和掌握. 而了解Kernel正是需要这些命令的指引, 不断深入理解其基本的内容. 下 ...
- Hudson和Jenkins的关系
Jenkins is an open source continuous integration tool written in Java. The project was forked from H ...
- DevExpress TreeList GridView 样式设置
1.GridView 样式设置 this.gridViewUser.PaintStyleName = "Flat"; 2.TreeList 样式设置 this.treeListDe ...