当前位置:网站首页>(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 .
边栏推荐
- RT thread flow notes I startup, schedule, thread
- appium1.22.x 版本后的 appium inspector 需单独安装
- Concurrent operation memory interaction
- JS function algorithm interview case
- How to connect the network: Chapter 1 CSDN creation punch in
- JS scope
- 【实战项目】自主web服务器
- Thesis reading_ Chinese medical model_ eHealth
- Wechat applet waterfall flow and pull up to the bottom
- Market status and development prospects of the global autonomous marine glider industry in 2022
猜你喜欢
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
微服务常见面试题
On typescript and grammar
Thesis reading_ ICD code_ MSMN
Celebrate the new year together
BIO、NIO、AIO区别
Basic use of Metasploit penetration testing framework
BTC-密码学原理
Audio Focus Series: write a demo to understand audio focus and audiomananger
【实战项目】自主web服务器
随机推荐
Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
Market status and development prospects of the global autonomous marine glider industry in 2022
sql语句模糊查询遇到的问题
1107 social clusters (30 points)
Kept hot standby and haproxy
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Botu uses peek and poke for IO mapping
Wechat applet distance and map
Notes | numpy-10 Iterative array
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Silent authorization login and registration of wechat applet
Thesis reading_ ICD code_ MSMN
Make your own dataset
Go language interface learning notes Continued
Overview of basic knowledge of C language
[basic grammar] Snake game written in C language
Notes | numpy-08 Advanced index
Common methods of JS array
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)