Python Matplotlib.plot Update Image Questions

Source: Internet
Author: User

1. Recently in the test of a device, after acquiring some devices need a frame to display the image, often using Python, so the use of matplotlib for image operation

Data structure: Timesatamp polar_distance horizontal_angle refelectivity_intensity, all data types are float, stored in files and separated by spaces

Import Mathimport Matplotlib.pyplot as plt#read data from FileDef loaddata (filename):    inFile = open (filename, ' r ') 
     #declare Both 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. displaying polar coordinates images

defGenerateimagefromdata (polar,angle,inten):D2R= math.pi/180 forIinchRange (len (polar)): Angle[i]= d2r* (Angle[i] +180)plt.ion ()
#inreactive Code AX
= Plt.subplot (111, projection='Polar') forIinchRange (100): C= Ax.scatter (angle[i*167:(i+1) *167], polar[i*167:(i+1) *167], S = 10) Plt.show () Plt.pause (1)

3. Calling functions

If __name__== "__main__":    (Polar,angle,inten) = LoadData ("CloudData.txt")    generateimagefromdata (Polar, Angle,inten)

When Pl.ion () is added to a drawing statement, interactive mode is turned on. At this point the Python interpreter interprets all the commands and gives you a picture, but does not end the conversation, but waits for you to communicate with him. If you continue to add statements to your code, you'll see the changes in the graphics in real time after run. When Pl.ioff () is added to a drawing statement or no pl.ion () is added, the interactive mode is turned off.

4. Another example

#!/usr/bin/env python3#-*-coding:utf-8-*-"" "Created on Thu Nov 21:26:17 2017@author:xx" "" Import Matplotlib.pylab A  S PLT Import numpy as NP import math #clear images plt.close () FIG = plt.figure () ax = Fig.add_subplot (111) #ratio of X and Y Axisax.axis ("equal") #enable grid of Imageax.grid (True) #activate inreactivate modeplt.ion () init_x = 0.0init_y = 3.5init_ Angle = 45init_wind_speed = 3print ("inreactive mode Beginning") Try: for     T in range:        x = init_x + Init_wind_spe Ed*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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.