在matplotlib中创建子图的多种方式

Python Matplotlib 子图 使用python绘制多个子图的场景,子图的布局,数据显示,以及图形组合问题解决。 阅读详情

在用Matplotlib绘制图像时,有时候需要从多个角度对数据进行对比。为此子图的概念便提了出来,子图可以在较大的图形中同时放置一组较小的坐标轴。这些子图可能是画中画、网格图,或者是其他更复杂的布局形式。

创建子图常用的可以有如下三种方式。

  • 使用add_subplot()面向对象的方式来创建子图

使用面向对象的方式创建子图前,需要创建一个figure对象,如fig = plt.figure(),然后在图像布局中绘制子图,下列例子中,我们用fig.add_subplot(221)绘制了2行2列子图,而221代表创建2行2列一共4个子图,并从左往右第1个子图开始绘图。假设我们要绘制2行6列子图,当画到第10块子图时,那么第10块该怎么写呢?2610是不行的,可以用另一种方式(2, 6, 10)

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(100)

# 创建图像布局对象fig
fig = plt.figure(figsize = (12, 6))

# 221代表创建2行2列一共4个子图,并从左往右第1个子图开始绘图。
ax1 = fig.add_subplot(221)
ax1.plot(x, x)

ax2 = fig.add_subplot(222)
ax2.plot(x, -x)

ax3 = fig.add_subplot(223)
ax3.plot(x, x ** 2)

ax4 = fig.add_subplot(224)
ax4.plot(-x, x ** 2)

plt.show()

显示的图像如下:
在这里插入图片描述

  • 使用pyplot方式直接创建子图

除了使用上面,面向对象的方式创建图外,我们还可以直接使用pyploy(也就是我们声明的别名plt)直接创建子图对象,而不需要先声明实例对象的方式去创建,最终绘图得到的图像是一模一样的。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(100)

plt.figure(figsize = (12, 6))
# 先画好子图具体位置
plt.subplot(221)
# 在该子图下绘图
plt.plot(x, x)

plt.subplot(222)
plt.plot(x, -x)

plt.subplot(223)
plt.plot(x, x ** 2)

plt.subplot(224)
plt.plot(-x, x ** 2)

plt.show()
  • 使用subplots创建多个子图

注意:如果设置的nrows = 1,ncols = 3也就是1行3列的话,axes的引用格式就不是axes[0][1],axes[0][2], axes[0][3]这样子。而是直接使用axes[0], axes[1], axes[2], 不然会报错。因为默认1行就不算是多维数组,所以不需要多维数组访问的方式。

import numpy as np
import matplotlib.pyplot as plt

# 将画布分割为2行2列,起始值为0。
fig, axes = plt.subplots(figsize = (12, 6), nrows = 2, ncols = 2)
# 给第1行第1列绘图
axes[0][0].hist(np.random.rand(500), label = 'hist0', edgecolor = 'black')
# 给图形添加标签
axes[0][0].legend()

axes[0][1].hist(np.random.rand(500), label = 'hist1', edgecolor = 'black')
axes[0][1].legend()

axes[1][0].hist(np.random.rand(500), label = 'hist2', edgecolor = 'black')
axes[1][0].legend()

axes[1][1].hist(np.random.rand(500), label = 'hist3', edgecolor = 'black')
axes[1][1].legend()

plt.show()

显示的图像如下:
在这里插入图片描述

除此之外,如果要实现更复杂的排列方式,比如说实现不规则的多行多子列图有没有什么办法呢?万能的matplotlib图库当然有办法,那就是使用plt.GridSpec(),不过plt.GridSpec()对象本身不能直接创建一个图形,他其实只是plt.subplot()命令可以识别的一个简易接口。

  • plt.GridSpec:实现更复杂的排列方式
import numpy as np
import matplotlib.pyplot as plt

# 声明一个GridSpec对象实例,创建的是2行3列的图像布局。
grid = plt.GridSpec(nrows=2, ncols=3, wspace=0.2, hspace=0.2)

# 设置整个图像大小。
plt.figure(figsize = (12, 6))
# 第一个子图的具体排列位置为(0,0)。
plt.subplot(grid[0, 0])
plt.hist(np.random.rand(50), orientation='horizontal', edgecolor = 'black')

plt.subplot(grid[0, 1:])
plt.scatter(np.random.rand(100),np.random.rand(100), color = 'r', edgecolor = 'black')

plt.subplot(grid[1, :2])
plt.plot(np.arange(10), np.random.rand(10))

plt.subplot(grid[1, 2]);
plt.plot(np.arange(10), np.arange(10) ** 2)

plt.show()

可以看到最终的绘制效果图如下,实现了不规则的图形。

在这里插入图片描述

这个例子中有几个参数要特别说明下,因为一开始会让不少人感到困惑,就是关于创建不规则子图的参数指定,因为这决定了子图的排列规则。例子中4个子图的位置分别是grid[0, 0]、grid[0, 1:]、grid[1, :2]、grid[1, 2]它们到底代表着什么呢,怎么理解呢。

可以这样理解,一开始我们声明创建的是2行3列的一个图像布局网格,我们可以想象成我们创建的是一个二维数组,类似如下这样,如果一行的宽度按100%计算的话,每个元素占据的宽度可以理解为33.33%:

[1, 2, 3]
[4, 5, 6]

第一个子图的位置是grid[0, 0]:按照这个[0, 0]的下标取值为第1行第1列的元素,得到的是1这个元素位置宽度(大概是33.33%的宽度)。

第二个子图的位置是grid[0, 1:]:按照这个[0, 1:]的下标取值为第1行第2列的之后所有的元素,得到的是2, 3这个元素位置宽度。所以你可以从效果图中看到第2个子图占据了第一行一大半的宽度(大概是66.66%的宽度)。

第三个子图的位置是grid[1, :2]:按照这个[1, :2]的下标取值为第2行第1列起到第3列之间所有的元素,得到的是4, 5这个元素位置宽度。所以你可以从效果图中看到第3个子图占据了第二行一大半的宽度(大概是66.66%的宽度)。

第四个子图的位置是grid[1, 2]:按照这个[1, 2]的下标取值为第2行第3列的元素,得到的是6这个元素位置宽度。所以你可以从效果图中看到第4个子图只占据了一个元素的宽度(大概是33.33%的宽度)。

python数据可视化玩转Matplotlib subplot子图操作,四个子图(一包四),三个子图,子图拉伸 子图是Matplotlib中强大的功能之一。使用函数,您可以方便地创建多个子图,并使用Axes对象绘制各种图形。使用各种选项,例如figsizewspace和hspace参数,以及GridSpec对象,可以更改子图的大小、位置和间距。 阅读详情

相关推荐

Matplotlib 多子图绘制

多子图绘制的N种方法。

早起CaiCai的学习空间 1536

Matplotlib(二)—— 子图

Matplotlib(二): 子图

share16的博客 4690

matplotlib子图绘制

从绘图流程出发,【plt】图像有三个层级,依次是窗口、坐标系以及图像。在一个坐标系中可以有多条曲线,即表示多个图像;相应地在一个窗口中,也应该可以容纳多组坐标系,每组坐标便是一个子图。

微小冷的学习笔记 1392

【数据分析之道-Matplotlib(三)】Matplotlib 绘制子图

Matplotlib支持多种绘制多图的方法,其中最常用的是subplot和subplots函数。subplot函数可以将一个图像分成若干个小区域,并在其中绘制子图,而subplots函数可以一次性创建多个子图,并返回一个包含所有子图的数组对象。

阿极的博客 6392

AP发票批量付款程序(WEB ADI)

CREATE OR REPLACE PACKAGE MEW_AP_BATCH_PAYMENTS_PKG IS   PROCEDURE MAIN(P_BATCH_ID          NUMBER                 ,P_ORG_ID            NUMBER                 ,P_BANK_ACCOUNT_NAME VARCHAR2

储藏室 5050

ONFI5.0命令字实战指南:从基础操作到高级应用

本文深入解析ONFI5.0协议的核心——命令字,提供从基础操作到高级应用的实战指南。详细拆解了NAND闪存的复位、读状态、数据读取(00-30)、页编程(80-10)和块擦除(60-D0)等关键命令周期,并探讨了多平面操作与缓存操作等高级性能优化技巧,帮助开发者高效、稳定地与NAND芯片进行底层交互。

vscode5coder的博客 462

python中matplotlib介绍_python中matplotlib库的相关介绍

import matplotlib.pyplot as pltimport numpy as npfrom pylab import *plt.bar([1,3,5,7,9],[5,2,7,8,2]) #创建条形图plt.xlabel('bar number') #x轴标签plt.ylabel('bar height')plt.show()多个图的创建import matplo...

weixin_35117981的博客 255

MFC 修改CheckBox的文本颜色方法

设置主题 这一步是必须的,不可省略。 BOOL CMFCApplication1Dlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 // 设置主题 HWND

Kim的博客 2249

matplotlib.pyplot.subplot

matplotlib.pyplot.subplot

荣耀之路 3552

保姆级教程:用海思PQTool搞定ISP图像调试,从参数读取到固件烧录全流程

本文提供海思PQTool的ISP图像调试全流程指南,从参数读取、实时调试到固件烧录,涵盖环境配置、核心功能解析、参数固化及生产部署。通过实战案例和避坑指南,帮助开发者高效提升图像质量,适用于海思开发板的ISP调试与优化。

weixin_30872337的博客 279

中兴SDH设备开局及业务配置

中兴SDH设备开局及业务配置 1.设备开局(S200-----S325) A.开电之后,按住截铃(bell off)开关,直至NCP告警灯变成橙色; B.此时,设备进入Download状态,设备IP为:192.192.192.11/24; 2.用交叉线(568A)将设备的QX口连接至电脑,电脑配置和设备相同网段的IP信息; 3.在电脑上测试连通性:pin...

weixin_33897722的博客 3996

matplotlib的一些代码

Matplotlib Python 画图教程 (莫烦Python)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16378354/?from=search&seid=16336534570780842214"""画3D图""" import numpy as np import matplotlib.p...

weixin_30797027的博客 415

为分析表明卡诺电池技术(或热泵式储电技术)-是目前最佳的储能技术!!!-2021年

卡诺电池(Carnot Battery)是一种基于热力学循环的储能技术,其核心原理是通过热力循环将电能转化为热能存储,并在需要时将热能重新转换为电能输出。这种技术得名于热力学中的卡诺循环原理,由法国工程师卡诺于1824年提出。

qq_15963745的博客 655

Matplotlib绘制图形之初步介绍

Matplotlib是一个Python的绘图库,它可与 NumPy 一起使用,可以代替Matlab使用。 其优点有:(1)将数据进行可视化,使数据更直观;(2) 使数据更加更具有说服力。由于Matplotlib是第三方库,所以需要安装它才可以使用。 安装命令: pip install matplotlib 安装可参考官网: https://matplotlib.org/users/installing.html 注意: Matplotlib3.0要求python3版本才可安装使用。 图片与子图的介绍 Mat

m0_45209371的博客 1067

EtherCAT主站SOEM -- 0 -- 该EtherCAT主站SOEM专栏后续安排

SOEM(Simple Open EtherCAT Master)是一个开源的EtherCAT主站库,允许开发者构建自定义的EtherCAT主站应用程序。EtherCAT是一种实时以太网通信协议,广泛应用于工业自动化和机器控制领域。开源性质:SOEM是一个开源项目,这意味着开发者可以自由地查看、修改和分发代码。这使其成为工业自动化领域的一个强大工具,可以根据具体需求进行定制。EtherCAT主站实现:SOEM库提供了一个完整的EtherCAT主站实现,允许主站与多个EtherCAT从站设备进行通信。

常驻客栈的博客--嵌入式EtherCAT 6664

RAG系统中Embedding模型选型实战

本文详细介绍了RAG系统中Embedding模型选型实战,希望能对学习RAG的同学们有所帮助。 文章目录 1. 前言 2. 思路解析 3. 测评数据集构建 3.1 步骤一 3.2 步骤二 3.3 数据示例 3.4 总结 4. 实战代码 4.1 本地模型 4.2 使用第三方的Embedding模型API

herosunly的博客 17万+

深入了解Matplotlib中的子图创建方法

在本博客中,我们深入了解了Matplotlib中的子图创建方法,主要聚焦于add_axes()和add_subplot()两种常用方法。这两种方法在创建子图时各具优缺点,选择合适的方法取决于具体的需求和布局要求。

m0_74195174的博客 2299

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

matplotlib.pyplot创建子图的方式

一个作图的窗口就是一个Figure, 在Figure上可以有很多个Axes/Subplot,每一个Axes/Subplot为一个单独的绘图区,可以在上面绘图。其中每一个Axes/subplot, 有XAxis,YAxis,在上面可以标出刻度,刻度的范围,以及X、Y轴的标签label。 1. 面向对象的方式 1.1 创建Figure figure(num=None, figsize=No...

prosmail的博客 2894

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Python Matplotlib subplot函数详解:创建子图

使用 Matplotlib 除可以生成包含多条折线的复式折线图之外,它还允许在一张数据图上包含多个子图。 调用subplot() 函数可以创建一个子图,然后程序就可以在子图上进行绘制。subplot(nrows, ncols, index, **kwargs) 函数的 nrows 参数指定将数据图区域分成多少行;ncols 参数指定将数据图区域分成多少列;index 参数指定获取第几个区域。 ...

人生苦短, 还不用Python? 1万+

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Matplotlib绘图基础——创建画布、子图、图例等

Matplotlib中应用最广的是matplotlib.pyplot模块,其绘制遵循以下流程:创建画布—(是否创建子图—选定子图)—添加标题、添加xy轴名称、修改xy轴刻度与范围—绘制图形—添加图例—完成绘制—保存图形—显示图形 1.创建画布 首先构建一张空白画布,并可选择是否划分成多个画布。当只绘制一幅时,可省略该步骤。创建画布函数为:plt.figure()。...

zm_1900的博客 1万+

Matplotlib画布和子图创建

@

hc645395861的博客 2223

matplotlib创建子图的四种方法

文章目录方法一,利用subplots()方法二,利用add_subplot()创建子图方法三,利用pandas+plot()直接创建子图 方法一,利用subplots() import matplotlib.pyplot as plt fig,axes=plt.subplots(2,2,figsize=(5,4), sharex=False, ...

辉的博客 6699

调整Matplotlib子图的大小

前段时间就遇到了这个问题,一直忘了写,今晚夜深人静总结一波~ 问题 我相信,看到这篇博客的人,你肯定已经会使用Matplotlib中的pyplot画图。 比如下面这种图 你也应该会调整单个图的大小了,就是使用如下语句控制单个图形figure的大小,比如我这里设的8*6的。 fig3 = plt.figure(figsize=(8,6)) 但随着继续深入的学习,有时我们很有必要将两个图画在一起,来做对比,所以你也应该会在一个画布上画多个子图了。比如下图 即是通过subplot实现...

little_spice的博客 2万+

Matplotlib子图

子图 **有时候我们需要从多个角度进行数据的比较、分析,因此就需要用到子图。**子图的本质是在一个较大的图形中同时放置一组较小的坐标轴,布局形式可以多种多样,不拘泥于我们在第五集中举的那种网格图的形式。 一般化的子图 我们先进行一般化的子图布局。 首先要创建各个子图的坐标轴,传入一个四元列表参数:[x,y,width,height],用来表示这个子图坐标轴原点的x坐标、y坐标,以及宽和高。值得注意的是,这四个值的取值范围都是[0,1],我们约定整个大图的左下端为原点(0,0),右上端为(1,1)。那么x,y

Joey9898的博客 3655

Python Matplotlib 子图绘制

Matplotlib 是 Python 中最流行的绘图库之一,广泛用于数据可视化。它支持多种图表类型,包括折线图、散点图、条形图等。通过 Matplotlib,我们可以创建静态、动态和交互式的图表。通过这两个示例,我们可以看到subplot()和subplots()的基本用法。subplots()方法返回一个axes数组,允许我们更方便地对每个子图进行设置。在实际应用中,我们常常需要对子图进行样式和布局的自定义,以使得图表更加美观和易于解读。

chusheng1840的博客 2088

matplotlib 基础_子图创建

matplotlib基础子图创建

qq_44511163的博客 5091
上一篇: 路径处理库pathlib使用详解
下一篇: pandas中map和applymap及apply的区别
itanders
博客等级 码龄19年 178粉丝 177原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值