当前位置:网站首页>(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 .
边栏推荐
- Handler understands the record
- 1087 all roads lead to Rome (30 points)
- Class loading mechanism (detailed explanation of the whole process)
- Force GCC to compile 32-bit programs on 64 bit platform
- 5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
- What is UUID
- 112 stucked keyboard (20 points)
- ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
- Make your own dataset
- leetcode860. Lemonade change
猜你喜欢

Thesis reading_ Chinese NLP_ ELECTRA
![[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)](/img/af/8dfa783c87363a9d75c52e7680d508.jpg)
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)

Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)

Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)

appium1.22.x 版本後的 appium inspector 需單獨安裝
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree

乾元通多卡聚合路由器的技术解析

Shuttle + alluxio accelerated memory shuffle take-off

音频焦点系列:手写一个demo理解音频焦点与AudioMananger

M1 Pro install redis
随机推荐
Notes | numpy-07 Slice and index
Webapidom get page elements
乾元通多卡聚合路由器的技术解析
1107 social clusters (30 points)
Retirement plan fails, 64 year old programmer starts work again
Thesis reading_ Tsinghua Ernie
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
1114 family property (25 points)
MySQL master-slave configuration
Notes | numpy-09 Broadcast
Basic knowledge of reflection (detailed explanation)
JDBC database operation
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Celebrate the new year together
Shuttle + alluxio accelerated memory shuffle take-off
JQ style, element operation, effect, filtering method and transformation, event object
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
SSM framework integration