当前位置:网站首页>Preparation Notes: Matplotlib learning notes a
Preparation Notes: Matplotlib learning notes a
2022-07-19 12:32:00 【Raine_ Yang】
1 establish figure Object to start drawing
import matplotlib.pyplot as plt
fig = plt.figure()
2 Create an axis as the drawing base
ax = fig.add_subplot(111)
ax.set(xlim=[0.5, 4.5], ylim=[-2, 8], title='An Example Axes',
ylabel='Y-Axis', xlabel='X-Axis')
plt.show()
fig.add_subplot() It refers to dividing the canvas into several equal parts .111 For the entire canvas
ax.set In the function xlim by x Upper and lower limits of coordinates ,ylim by y Upper and lower limits of coordinates ,title Is the chart name ,ylabel,xlable by y Axis and x The name of the shaft

fig = plt.figure()
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)

Divide the canvas in half, and you can draw 4 Map , The third parameter corresponds to the canvas position
Create multiple axes at once and save them to a two-dimensional array
fig, axes = plt.subplots(nrows=2, ncols=2)
axes[0,0].set(title='Upper Left')
axes[0,1].set(title='Upper Right')
axes[1,0].set(title='Lower Left')
axes[1,1].set(title='Lower Right')
Use plot Function line , The first two parameters correspond to x,y Axis data , You can add colors later , Line type and other parameters
x = np.linspace(0, np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)
ax1.plot(x, y_sin)
ax2.plot(x, y_sin, 'go--', linewidth=2, markersize=12)
ax3.plot(x, y_cos, color='red', marker='+', linestyle='dashed')

fig.clear()
Clear the canvas , Clear all axes and images
The string key drawing of the incoming dictionary :
x = np.linspace(0, 10, 200)
data_obj = {
'x': x,
'y1': 2 * x + 1,
'y2': 3 * x + 1.2,
'mean': 0.5 * x * np.cos(2*x) + 2.5 * x + 1.1}
# Plot the "centerline" with `plot`
ax.plot('x', 'mean', color='black', data=data_obj)
plt.show()
Here, the string is passed in the data part , These strings correspond to data_obj The key inside , Pass in the dictionary 、data_obj As data It can automatically read the value corresponding to the key for drawing 
matplotlib And the scatter chart , Bar chart , Histogram , The pie chart , Box diagram , Bubble chart , Contour and other options , See article https://blog.csdn.net/qq_34859482/article/details/80617391
边栏推荐
- 招生宣传-江南大学
- SQL盲注详解
- RAID 磁盘阵列详解,RAID分类及优缺点
- Pytorch version: yolov4 integrating attention and mobilenet
- MIHA tour 2023 autumn recruitment officially begins ~ early approval has the opportunity to avoid written examination!
- 我最喜欢的10个机器学习公众号
- Notes on the fifth day
- Genesis and bluerun ventures have in-depth exchanges
- In 2022, how to choose cross end technology solutions?
- 超声波传感器系列文章汇总
猜你喜欢

Solution: code error: error reported by error could not resolve

RAID 磁盘阵列详解,RAID分类及优缺点

Configuring OSPF experiment in mGRE environment

mysql中对于数据库的基本操作

Dynamic memory planning

OpenCV 教程 03: 如何跟踪视频中的某一对象

Softmax和Cross-entropy是什么关系?

Gradient button function button drawing C language example

Core base station_ The error "no gateways configured" is reported when starting the CPA file

云犀聚焦店播解决方案,加速全球化布局
随机推荐
2022 low voltage electrician examination questions and online simulation examination
How to apply applet container technology to develop hybrid app
对Rapidly-exploring Random Trees(RRT)路径规划方法的理解
Relationship and difference between wav and PCM
Machine learning (I) Wu enda
Machine learning Assignment 1
Solution: function RGB is missing argument $green Problems of
Hcip fourth day notes
Redis集群主备缓存区满了导致主备频繁倒换
HICP first day notes
OpenCV 教程 03: 如何跟踪视频中的某一对象
Travail du quatrième jour
C # from introduction to mastery Part II: C # basic grammar
go web
Pytorch version: yolov4 integrating attention and mobilenet
Leetcode 239. Sliding window maximum
Matlab (4) functions and files
电路故障的分析简略
psd. JS parsing PSD file
HCIP(4)