当前位置:网站首页>(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 .
边栏推荐
- BTC-密码学原理
- 微服务常见面试题
- Yolov5 model construction source code details | CSDN creation punch in
- 1111 online map (30 points)
- Shallow and first code
- Messy change of mouse style in win system
- 最大连续子段和(动态规划,递归,递推)
- Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
- Review the configuration of vscode to develop golang
- Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
猜你喜欢

leetcode452. Detonate the balloon with the minimum number of arrows

【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)

微服务常见面试题

Handler understands the record
![[basic grammar] C language uses for loop to print Pentagram](/img/9e/021c6c0e748e0981d4233f74c83e76.jpg)
[basic grammar] C language uses for loop to print Pentagram

Gbase8s composite index (I)

Shuttle + alluxio accelerated memory shuffle take-off

Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément

Burp suite plug-in based on actual combat uses tips
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
随机推荐
leetcode435. Non overlapping interval
leetcode406. Rebuild the queue based on height
1103 integer factorization (30 points)
【实战项目】自主web服务器
Webapidom get page elements
Notes | numpy-08 Advanced index
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Three representations of signed numbers: original code, inverse code and complement code
Retirement plan fails, 64 year old programmer starts work again
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
1119 pre- and post order traversals (30 points)
[basic grammar] C language uses for loop to print Pentagram
1099 build a binary search tree (30 points)
Pan details of deep learning
Keepalived热备与HAProxy
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
Thesis reading_ Tsinghua Ernie
Kept hot standby and haproxy