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. ...
随机推荐
- Spring_总结_04_高级配置(二)_条件注解@Conditional
一.前言 本文承接上一节:Spring_总结_04_高级配置(一)之Profile 在上一节,我们了解到 Profile 为不同环境下使用不同的配置提供了支持,那么Profile到底是如何实现的呢?其 ...
- DataGridView绑定数据源的几种方式
使用DataGridView控件,可以显示和编辑来自多种不同类型的数据源的表格数据. 将数据绑定到DataGridView控件非常简单和直观,在大多数情况下,只需设置DataSource属性即可.在绑 ...
- SQL使用指南(1)—— 数据定义语言(DDL)
1.使用create 语句创建表 CREATE TABLE table_name (column_name datatype[null|not null], column_name datatype[ ...
- hdu4771 Stealing Harry Potter's Precious(DFS,BFS)
练习dfs和bfs的好题. #include<iostream> #include<cstdio> #include<cstdlib> #include<cs ...
- Linux中几个实用快捷键
返回上层目录: cd .. 命令提示符: user@ubuntu: @之前的部分为当前用户ID名称: @之后冒号之前是主机名称 sudo :(Superusers Do) 以超级用户执行 在相对路径 ...
- 二、python沉淀之路~~字符串属性(str)
1.capitalize的用法:即将输出字符串首字母大写 test = "heLLo" v = test.capitalize() print(v) 结果:Hello. 2.cas ...
- HttpContext是干什么的
这是MSDN对HttpContext的说明: HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息. (网上说是上下文信息,啥又叫上下文呢?个人感觉说的不 ...
- 如何测试远端TCP和UDP端口是否开放
项目遇到问题时首先排查网络是否正常是一个重要的方面.遇到很多次,同事找我解决问题,最后发现却是IP或端口不通的问题.然而就是这么个简单的问题,对方却花费了甚至一天的时间排查原因. 现在大部分项目都是用 ...
- HIVE-执行distribute by时报错的解决过程---之如何分析hive执行的错误并解决
在执行一条HIVE语句的时候报了以下错误,重新检查了所有步骤,重启所有服务,发现没有问题. 但发现一个有趣的事情 1,select sno,sname,sex,sage,sdept from stud ...
- Java实现Bag类
Java实现Bag类 import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Scan ...