当前位置:网站首页>(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
2022-07-03 05:09:00 【Interval】
import matplotlib.pyplot as plt
# Prepare the data .
x=np.arange(3)
y1=np.random.rand((3))
y2=np.random.rand((3))
rough
# Get the plot area and subgraph .
fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,4))# Specify the drawing area as (10,4), And one row and two columns , By default, the two columns each occupy half , namely (5,4)(5,4)
ax1.plot(x,y1)
ax2.plot(x,y2)
fine
1. scale
The scale sum of the subgraph plt The use of that scale is different .
The latter is :
plt.xticks(x,label)# You can go to x Fill in label value .
But the usage of subgraph is :
ax1.set_xticks(x)# stay x Mark the number at the position of .
ax1.set_xticklabels(label)# stay x Mark label at .
The effect is as follows :
# Get the plot area and subgraph .
fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,4))# Specify the drawing area as (10,4), And one row and two columns , By default, the two columns each occupy half , namely (5,4)(5,4)
ax1.plot(x,y1)
ax2.plot(x,y2)
ax1.set_xticks(x)# stay x Mark the number at the position of .
# ax1.set_xticklabels(label)# stay x Mark label at .
# Get the plot area and subgraph .
fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,4))# Specify the drawing area as (10,4), And one row and two columns , By default, the two columns each occupy half , namely (5,4)(5,4)
ax1.plot(x,y1)
ax2.plot(x,y2)
ax1.set_xticks(x)# stay x Mark the number at the position of .
label=["a","b","c"]
ax1.set_xticklabels(label)# stay x Mark label at .
2. size
Now we can see , The whole drawing area we set up above is (10,4), Then the default is half , So how to finely control the size of each subgraph ?
# Get the plot area and subgraph .
fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,4))# Specify the drawing area as (10,4), And one row and two columns , By default, the two columns each occupy half , namely (5,4)(5,4)
ax1.plot(x,y1)
ax2.plot(x,y2)
ax1.set_position((0.1,0.1,0.8,0.8))# take ax1 The lower left corner of is placed in the drawing area 0.1,0.1 Location (0.1 Refers to the drawing area 10% It means ).ax1 After the lower left corner of is placed , Wide for 80%, High for 80%. Be careful , here ax1 The position of the upper right corner of is 0.9,0.9.
ax2.set_position((0.9,0.9,0.1,0.1))# So here from 0.9 Start , Otherwise it will overlap . Then only account for 0.1, Just finished drawing area .
You can see , A big , One small .
trick
In fact, if you have time , Subgraphs ( Axis domain ) The official document of this class says ,axes Other properties can be seen https://matplotlib.org/stable/api/axes_api.html?highlight=axes#module-matplotlib.axes.
All in all , Have the thought of class ,axes( Subgraphs ) Is in figure( canvas ) Medium . Then why is it difficult to learn when it comes to drawing ? My feeling is that the official for the convenience of everyone , Building subgraphs , We are not going to construct axes class , Instead, call a variety of methods , For example, above
subplots()
It looks like , Easy to get started , Convenient for novices , But it has greatly damaged the understanding of advanced people , Ah .
According to the thought of class , We should be as follows :
First create the drawing area object figure, Then pass this object and the location of the subgraph axes Class in the constructor , Get the subgraph . Then draw .
边栏推荐
- leetcode860. Lemonade change
- 【实战项目】自主web服务器
- M1 Pro install redis
- Notes | numpy-09 Broadcast
- The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
- 112 stucked keyboard (20 points)
- How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
- Celebrate the new year together
- Redis 过期淘汰机制
- The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
猜你喜欢
(完美解决)matplotlib图例(legend)如何自由设置其位置
appium1.22.x 版本後的 appium inspector 需單獨安裝
Overview of basic knowledge of C language
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Web APIs exclusivity
Kept hot standby and haproxy
BIO、NIO、AIO区别
(subplots用法)matplotlib如何绘制多个子图(轴域)
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
随机推荐
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
M1 Pro install redis
BIO、NIO、AIO区别
2022-02-11 daily clock in: problem fine brush
乾元通多卡聚合路由器的技术解析
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Online VR model display - 3D visual display solution
动态规划——相关概念,(数塔问题)
Flutter monitors volume to realize waveform visualization of audio
50 practical applications of R language (36) - data visualization from basic to advanced
leetcode452. Detonate the balloon with the minimum number of arrows
Common methods of JS array
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Detailed explanation of yolov5 training own data set
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Introduction to deep learning - definition Introduction (I)
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
MySQL master-slave configuration
1118 birds in forest (25 points)
Botu uses peek and poke for IO mapping