current position:Home>Python Matplotlib drawing graphics
Python Matplotlib drawing graphics
2022-02-01 00:07:48 【Little cute in the circle of friends】
This is my participation 11 The fourth of the yuegengwen challenge 18 God , Check out the activity details :2021 One last more challenge
Preface
We are facing matplotlib Module underlying structure learning , For its pyplot class ( Script layer ) Class to draw a line chart 、 Histogram 、 The pie chart 、 Histogram and other statistical charts , List previous articles as follows .
-
matplotlib The underlying structure :matplotlib The module is divided into script layer 、 Art layer and back end , Collaborative workflow learning
-
matplotlib Draw line chart : Yes pyplot.plot() Draw a line chart and summarize the related attributes
-
matplotlib Draw a histogram : Yes pyplot.bar() Draw the relevant attributes of the Shao histogram to summarize and explain
-
matplotlib Draw histogram :pyolot.hist() Draw histogram related attributes for summary description
matplotlib The module not only provides the function of drawing statistical charts , It also supports drawing circles 、 Square 、 Rectangle and other graphics
In this issue , Let's learn to use matplotlib Module draw common graphics ,Let's go~
1. matplotlib.patches summary
matplotlib.patches A class dedicated to drawing graphics , In this class, we use Artist Base class
- pathes It's specially drawn 2D Graphic class
- patch The drawing defaults to rc params Set up
- patch The module provides up to 10 A graphic method to meet daily needs
2. Drawing method
Corresponding matplotlib The module says ,patches Class to draw a circle 、 ellipse 、 Rectangle and other graphic methods
Method | effect |
---|---|
patches.Rectangle(xy,width,height,angle=0) | Draw a rectangle |
patches.Polygon(xy) | Draw polygon |
patches.Arc(xy,width,height,angle=0) | Draw an ellipse |
patches.Circle(xy,radius) | Draw a circle |
patches.Ellipse(xy,width,height,angle=0.0) | Draw an ellipse |
patches.Arrow(x,y,dx,dy) | Draw the shear head |
patches.wedge(center,r,theta1,theta2,width) | Draw a wedge |
patches.PathPatch() | Draw a multi curve graph |
patches.FancyBboxPatch() | Draw a fancy graphic box |
patches.Line2D() | Draw lines |
3. Drawing graphics steps
stay matplotlib Module , The charts are made of figure、Axes and Axis Three basic elements , So when drawing graphics , The general steps are mainly composed of the following .
- Import matplotlib pyplot and patches class
import matplotlib.pyplot as plt
import matplotlib.patches as mpatch
Copy code
- Use subplots() Create subgraphs Axes object
fig,ax =plt.subplots()
Copy code
- call pathes Class to draw graphics, such as drawing a rectangle Rectangle()
Rect = mpatch.Rectangle((0.2,0.75),0.4,0.4,color="r")
Copy code
- Subgraphs Axes Object call set_xlim() and set_ylim Axis range
patches By default ,x The coordinate range of the axis is (0,1),y The coordinate range of the axis is (0,1)
ax.set_xlim(-2,5)
ax.set_ylim(-2,5)
Copy code
- Subgraphs Axes Object call add_patch() Method to add graphics
ax.add_patch(Rect)
Copy code
- call pyplot.show() Show graphics
4. Draw graphic properties
-
Set transparency
- keyword :alpha
- The value type is : floating-point
-
Set the color
- Set graphic keywords :color
- Set border keyword :edgecolor
- The value is optional :
- English words for color : Like red "red"
- Abbreviations of words indicating color, such as : Red "r", yellow "y"
- RGB Format : Hexadecimal format, such as "#88c999";(r,g,b) Tuple form
5. A profound
After learning the above sections , We draw circles in the chart 、 Rectangles and straight lines
def drawpicture():
fig,ax =plt.subplots()
Rect = mpatch.Rectangle((1,0.75),0.4,0.4,color="yellow",alpha=0.5)
Cri = mpatch.Circle((0,0),1,angle=30,color="pink",alpha=0.2,capstyle="round")
Py = mpatch.Arrow(1,2,2,2)
ax.set_xlim(-1,5)
ax.set_ylim(-1,5)
ax.add_patch(Rect)
ax.add_patch(Cri)
ax.add_patch(Py)
plt.show()
drawpicture()
Copy code
summary
In this issue , We are right. matplotlib Draw graphics related methods and steps to learn , In practice , It takes a lot of practice to use... More skillfully
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/202202010007455889.html
The sidebar is recommended
- leetcode 1560. Most Visited Sector in a Circular Track(python)
- leetcode 1995. Count Special Quadruplets(python)
- How to program based on interfaces using Python
- leetcode 1286. Iterator for Combination(python)
- leetcode 1418. Display Table of Food Orders in a Restaurant (python)
- Python Matplotlib drawing histogram
- Python development foundation summary (VII) database + FTP + character coding + source code security
- Python modular package management and import mechanism
- Django serialization (II)
- Python dataloader error "dataloader worker (PID XXX) is killed by signal" solution
guess what you like
-
apache2. 4 + Django + windows 10 Automated Deployment
-
leetcode 1222. Queens That Can Attack the King(python)
-
leetcode 1387. Sort Integers by The Power Value (python)
-
Tiger sniffing 24-hour praise device, a case with a crawler skill, python crawler lesson 7-9
-
Python object oriented programming 01: introduction classes and objects
-
Baidu Post: high definition Python
-
Python Matplotlib drawing contour map
-
Python crawler actual combat, requests module, python realizes IMDB movie top data visualization
-
Python classic: explain programming and development from simple to deep and step by step
-
Python implements URL availability monitoring and instant push
Random recommended
- Python avatar animation, come and generate your own animation avatar
- leetcode 1884. Egg Drop With 2 Eggs and N Floors(python)
- leetcode 1910. Remove All Occurrences of a Substring(python)
- Python and binary
- First acquaintance with Python class
- [Python data collection] scrapy book acquisition and coding analysis
- Python crawler from introduction to mastery (IV) extracting information from web pages
- Python crawler from entry to mastery (III) implementation of simple crawler
- The apscheduler module in Python implements scheduled tasks
- 1379. Find the same node in the cloned binary tree (Java / C + + / Python)
- Python connects redis, singleton and thread pool, and resolves problems encountered
- Python from 0 to 1 (day 11) - Python data application 1
- Python bisect module
- Python + OpenGL realizes real-time interactive writing on blocks with B-spline curves
- Use the properties of Python VTK implicit functions to select and cut data
- Learn these 10000 passages and become a humorous person in the IT workplace. Python crawler lessons 8-9
- leetcode 986. Interval List Intersections(python)
- leetcode 1860. Incremental Memory Leak(python)
- How to teach yourself Python? How long will it take?
- Python Matplotlib drawing pie chart
- Django paging (II)
- Concurrent. For Python concurrent programming Futures or multiprocessing?
- Programmers over the age of 25 can't know a few Chinese herbal medicines. Python crawler lessons 9-9
- Python crawler from introduction to pit full series of tutorials (detailed tutorial + various practical combat)
- The second bullet of class in Python
- Python object oriented programming 03: class inheritance and its derived terms
- How IOS developers learn Python Programming 13 - function 4
- Python crawler from introduction to mastery (VI) form and crawler login
- Python crawler from entry to mastery (V) challenges of dynamic web pages
- Deeply understand pandas to read excel, TXT, CSV files and other commands
- Daily python, Chapter 18, class
- "I just want to collect some plain photos in Python for machine learning," he said. "I believe you a ghost!"
- Django view
- Python implements filtering emoticons in text
- When winter comes, python chooses a coat with temperament for mom! Otherwise, there's really no way to start!
- Python crawler - get fund change information
- Highlight actor using Python VTK
- Python crawler actual combat: crawling southern weekend news articles
- leetcode 406. Queue Reconstruction by Height(python)
- leetcode 1043. Partition Array for Maximum Sum (python)