current position:Home>Python Matplotlib drawing streamline diagram
Python Matplotlib drawing streamline diagram
2022-02-01 16:26:03 【Little cute in the circle of friends】
This is my participation 11 The fourth of the yuegengwen challenge 28 God , Check out the activity details :2021 One last more challenge
Review
stay Python About drawing ,Mlab Provide open source matplotlib modular , You can not only draw a line chart 、 Histogram 、 Scatter diagram and other conventional diagrams , It also supports drawing quantity field diagram 、 spectrum 、 Picture of violin 、 Special drawings such as box drawing , Examples of previous articles can be found at .
-
specgram() Method to draw spectrum diagram for amplitude spectrum :matplotlib Plot the spectrum
-
boxplot() Methods draw a box diagram for data distribution :matplotlib Draw a box diagram
-
quiver() Methods to draw the quantity field diagram for electromagnetic field analysis :matplotlib Plot the quantity field
-
violinplot() Draw and display data distribution and probability :matplotlib Draw a picture of the violin
We often pay attention to the weather forecast in our daily life , When the season changes , The announcer will explain the air flow . During the weather forecast , Meteorological experts will draw the air flow according to the streamline map , To predict the local weather .
In this issue , We will learn matplotlib.pyplot.streamplot() Method related attribute learning ,let's go~
1. Streamline diagram Overview
-
What is a flow chart ?
- Streamline diagram is drawn by a combination of streamline and arrow , To represent the operation of the streamline in a certain period of time 、
- The arrow on the streamline chart indicates the flow direction , The shape on the streamline indicates the flow intensity
- Streamline diagram can be divided into airflow diagram 、 Isoanemometry 、 Elevation map, etc
- The flow lines in the flow line diagram can be merged 、 Convergence 、 Split cross , But it can't cross
-
Streamline diagram application scenario
- Streamline diagrams are usually used to study wind speed in meteorology 、 airflow 、 The flow direction of the ocean current
- Flow chart is an important chart for wind field analysis , The dilute density of the streamline is directly proportional to the wind speed
-
Method of obtaining streamline diagram
import matplotlib.pyplot as plt plt.streamplot(x,y,u,v) Copy code
2. Streamline properties
-
Set streamline density
- keyword :density
- The default value is :1
- The value type is : Floating point or tuple
- Control streamline density , When density=1 when , The grid will be divided into 30*30 grid
- For setting the density in each direction , Tuples can be used (x,y)
-
Set the streamline width
- keyword :linewidth
- The value type is : Floating point or two-dimensional array
- Use a two-dimensional array , You can change the line width of the streamline on the mesh
- The shape of the array must match u、v identical
-
Set streamline color
- keyword :color
- Values can be :
- English words for color : Like green "g"
- Abbreviations of words indicating color, such as : Red "r", yellow "y"
- RGB Format : Hexadecimal format, such as "#88c999";(r,g,b) Tuple form
- You can go to the color list
- When using cmap when , You need to color Set as a two-dimensional array , Otherwise it will not work
-
Set streamline scaling
- keyword :norm
- The default is to stretch the streamline to (0,1)
- Use... Only when the color is an array
-
Set streamline color system
- keyword :cmap
- The value form is : color table _r
- Available values commonly used are :'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens'
3. To draw a streamline diagram
- Import matplotlib.pyplot class
import matplotlib.pyplot as plt
Copy code
-
call numpy library arange()、random()、randint() Wait until you're ready x,y,u,v data
- x,y: One dimensional array / Two dimensional array
- u,v: Two dimensional array
- When it is a two-dimensional array , Can pass np.meshgrid(x,y),np.mgrid() establish
x = np.arange(1,10) y = np.arange(1,10) u,v = np.meshgrid(np.sin(x),np.sin(y)) Copy code
-
call pyplot.streamplot() Draw a streamline diagram
plt.streamplot(x,y,u,v,density=[0.5,1])
Copy code
- call pyplot.show() The rendering shows a streamline
plt.show()
Copy code
- Set up linewidth、color、cmap Property to draw a flow chart
plt.streamplot(x,y,u,v,density=[0.5,1],color=u,cmap="Accent_r",linewidth=3)
Copy code
4. A profound
We learned about the attributes related to drawing streamline diagram , Let's practice the starting point data of the control flow line
- call np.mgrid[] Definition x,y Two dimensional data
- call pyplot.streamplot() Method to draw a streamline diagram
- call pyplot.plot() Methods draw a line chart , Use marker Attribute tags
y,x= np.mgrid[-3:3:100j, -3:3:100j]
u = -1-x**2+y
v = 1+x-y**2
seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])
plt.streamplot(x,y,u,v,density=0.6,color=u,cmap="autumn",linewidth=1,start_points=seed_points.T)
plt.plot(seed_points[0],seed_points[1],"^",color="b")
plt.show()
Copy code
summary
In this issue , We are right. matplotlib.pyplot Provide streamplot() Methods to draw streamline graph and learn related attributes . Flowcharts are usually used in meteorology , Study the change of air flow .
The above is the content of this issue , Welcome big guys to praise and comment , See you next time ~
copyright notice
author[Little cute in the circle of friends],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011626007289.html
The sidebar is recommended
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
guess what you like
-
leetcode 1606. Find Servers That Handled Most Number of Requests(python)
-
leetcode 1611. Minimum One Bit Operations to Make Integers Zero(python)
-
06python learning notes - reading external text data
-
[Python] functions, higher-order functions, anonymous functions and function attributes
-
Python Networkx practice social network visualization
-
Data analysis starts from scratch, and pandas reads and writes CSV data
-
Python review (format string)
-
[pandas learning notes 01] powerful tool set for analyzing structured data
-
leetcode 147. Insertion Sort List(python)
-
apache2. 4 + windows deployment Django (multi site)
Random recommended
- Python data analysis - linear regression selection fund
- How to make a python SDK and upload and download private servers
- Python from 0 to 1 (day 20) - basic concepts of Python dictionary
- Django -- closure decorator regular expression
- Implementation of home page and back end of Vue + Django tourism network project
- Easy to use scaffold in Python
- [Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)
- [Python] function decorators and common decorators
- Explain the python streamlit framework in detail, which is used to build a beautiful data visualization web app, and practice making a garbage classification app
- Construction of the first Django project
- Python crawler actual combat, pyecharts module, python realizes the visualization of river review data
- Python series -- web crawler
- Plotly + pandas + sklearn: shoot the first shot of kaggle
- How to learn Python systematically?
- Analysis on several implementations of Python crawler data De duplication
- leetcode 1616. Split Two Strings to Make Palindrome (python)
- Python Matplotlib drawing violin diagram
- Python crawls a large number of beautiful pictures with 10 lines of code
- [tool] integrated use of firebase push function in Python project
- How to use Python to statistically analyze access logs?
- How IOS developers learn Python Programming 22 - Supplement 1
- Python can meet any API you need
- Python 3 process control statement
- The 20th of 120 Python crawlers, 1637. All the way business opportunity network joined in data collection
- Datetime of pandas time series preamble
- How to send payslips in Python
- [Python] closure and scope
- Application of Python Matplotlib color
- leetcode 1627. Graph Connectivity With Threshold (python)
- Python thread 08 uses queues to transform the transfer scenario
- Python: simple single player strange game (text)
- Daily python, chapter 27, Django template
- TCP / UDP communication based on Python socket
- Use of pandas timestamp index
- leetcode 148. Sort List(python)
- Confucius old book network data collection, take one anti three learning crawler, python crawler 120 cases, the 21st case
- [HTB] cap (datagram analysis, setuid capability: Python)
- How IOS developers learn Python Programming 23 - Supplement 2
- How to automatically identify n + 1 queries in Django applications (2)?
- Data analysis starts from scratch. Pandas reads HTML pages + data processing and analysis