matplotlib布局_Matplotlib多列,行跨度布局

matplotlib布局

For Visualization in Python, Matplotlib library has been the workhorse for quite some time now. It has held its own even after more nimble rivals with easier code interface and capabilities like seaborn, plotly, bokeh etc. have arrived on the scene. Though Matplotlib may lack the interactive capabilities of the new kids on the block, it does a more than adequate job of visualizing our data exploration tasks in Exploratory Data Analysis(EDA).

對于Python中的可視化而言,Matplotlib庫已經成為相當長一段時間的主力軍。 即使具有更靈活的代碼界面的更靈活的競爭對手以及諸如seaborn,plot,bokeh等功能已經出現在現場,它也保持了自己的地位。 盡管Matplotlib可能缺少新手的互動功能,但它在可視化探索性數據分析(EDA)中可視化我們的數據探索任務所做的工作遠遠不夠。

During EDA, one may come across situations where we want to display a group of related plots as part of a larger picture to drive home our insight. The subplot function of matplotlib does the job for us. However, in certain situations, we may want to combine several subplots and want to have different aspect ratios for each subplot. How can we achieve this layout, where, essentially some subplots span across several rows/columns of the overall figure?

在EDA期間,我們可能會遇到一些情況,在這些情況下,我們希望將一組相關的圖顯示為大圖的一部分,以推動我們的洞察力。 matplotlib的subplot功能為我們完成了工作。 但是,在某些情況下,我們可能希望合并多個子圖,并希望每個子圖具有不同的縱橫比。 我們如何才能實現這種布局,在此布局中,實際上有些子圖跨越了整個圖形的幾行/幾列?

Enter gridspec submodule of Matplotlib.

輸入gridspec子模塊。

Image for post

We first need to create an instance of GridSpec which allows us to specify the total number of rows and columns as arguments in the overall figure along with a figure object.

首先,我們需要創建一個GridSpec實例,該實例允許我們指定行和列的總數作為整體圖形中的參數以及figure對象。

Image for post

We store the GridSpec instance in a variable called gs and specify that we want to have 4 rows and 4 columns in the overall figure.

我們將GridSpec實例存儲在名為gs的變量中,并指定我們希望在整個圖中有4行4列。

Now, we need to specify the details of how each subplot will span the rows and columns in the overall figure. It is useful to make a rough sketch on paper as to how you want the subplots to be laid out, so that they don't overlap. Once done, we convey this information through the GridSpec object we created. The row/column span info is passed in the same index notation we use for subsetting arrays/dataframes with rows and column index numbers starting from zero and using the : to specify range. The GridSpec object with the index is passed to the add_subplot function of the figure object.

現在,我們需要指定每個子圖將如何跨越整個圖中的行和列的詳細信息。 在紙上粗略地繪制草圖,以了解子圖的布局方式是有用的,這樣子圖就不會重疊。 完成后,我們將通過創建的GridSpec對象傳達此信息。 行/列跨度信息以相同的索引符號傳遞,該索引符號用于設置數組和數據框,其中行和列的索引號從零開始,并使用:指定范圍。 所述GridSpec與索引對象被傳遞到add_subplot所述的功能figure的對象。

Image for post

We add an overall title for the figure and remove the ticks to visualize the layout better as the objective here is to demonstrate how we can achieve subplots spanning multiple rows /columns. When you implement this, obviously you will want to add your axis ticks, labels etc. from your dataframe and tweak the spacing and figure size to accommodate these plot elements.

我們為圖形添加一個整體標題,并刪除刻度線以更好地顯示布局,因為此處的目的是演示如何實現跨越多行/列的子圖。 當您實現此功能時,顯然您會希望從數據框中添加軸刻度,標簽等,并調整間距和圖形大小以容納這些繪圖元素。

Image for post

Boom! This may come in handy in multi-variable time series plots where we may want to show the time series plot stretching across the columns in the top row and other uni-variate, multi-variate visualization in the other subplots below. You can customize how your jigsaw looks like by specifying your row/columns in the overall figure and spans of your individual subplots.

繁榮! 這在多變量時間序列圖中可能會派上用場,在這里我們可能想要顯示跨越頂部行中各列的時間序列圖,并在下面的其他子圖中顯示其他單變量,多變量可視化。 您可以通過在整體圖形中指定行/列以及各個子圖的跨度來自定義拼圖的外觀。

In R, achieving the above is ridiculously easy with the patchwork package in a single line of code with nothing more than + and / operators and ( ) to even have nested subplots if you want to go bonkers. Click on the below link to see how you can get this done in R.

在R語言中,使用單行代碼中的patchwork程序包就可以輕松地實現上述目標,而只需要+/運算符和( )甚至嵌套嵌套的子圖就可以了。 單擊下面的鏈接,查看如何在R中完成此操作。

Thanks for reading. If you liked this article, you may also like the one below on how to do EDA with minimal lines of code with maximum output.

謝謝閱讀。 如果您喜歡這篇文章,那么您可能也喜歡以下關于如何用最少的代碼行和最大的輸出量進行EDA的文章。

Would love to hear your feedback and comments. Thanks!

很想聽聽您的反饋和意見。 謝謝!

翻譯自: https://towardsdatascience.com/matplotlib-multi-column-row-spanning-layouts-f026eb7c3c27

matplotlib布局

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390749.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390749.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390749.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Hadoop生態系統

大數據架構-Lambda Lambda架構由Storm的作者Nathan Marz提出。旨在設計出一個能滿足實時大數據系統關鍵特性的架構,具有高容錯、低延時和可擴展等特性。Lambda架構整合離線計算和實時計算,融合不可變性(Immutability)&#xff0c…

javascript之 原生document.querySelector和querySelectorAll方法

querySelector和querySelectorAll是W3C提供的 新的查詢接口,其主要特點如下: 1、querySelector只返回匹配的第一個元素,如果沒有匹配項,返回null。 2、querySelectorAll返回匹配的元素集合,如果沒有匹配項,…

RDBMS數據定時采集到HDFS

[toc] RDBMS數據定時采集到HDFS 前言 其實并不難,就是使用sqoop定時從MySQL中導入到HDFS中,主要是sqoop命令的使用和Linux腳本的操作這些知識。 場景 在我們的場景中,需要每天將數據庫中新增的用戶數據采集到HDFS中,數據庫中有tim…

單詞嵌入_神秘的文本分類:單詞嵌入簡介

單詞嵌入Natural language processing (NLP) is an old science that started in the 1950s. The Georgetown IBM experiment in 1954 was a big step towards a fully automated text translation. More than 60 Russian sentences were translated into English using simple…

使用Hadoop所需要的一些Linux基礎

Linux 概念 Linux 是一個類Unix操作系統,是 Unix 的一種,它 控制整個系統基本服務的核心程序 (kernel) 是由 Linus 帶頭開發出來的,「Linux」這個名稱便是以 「Linus’s unix」來命名的。 Linux泛指一類操作系統,具體的版本有&a…

python多項式回歸_Python從頭開始的多項式回歸

python多項式回歸Polynomial regression in an improved version of linear regression. If you know linear regression, it will be simple for you. If not, I will explain the formulas here in this article. There are other advanced and more efficient machine learn…

《Linux命令行與shell腳本編程大全 第3版》Linux命令行---4

以下為閱讀《Linux命令行與shell腳本編程大全 第3版》的讀書筆記,為了方便記錄,特地與書的內容保持同步,特意做成一節一次隨筆,特記錄如下: 《Linux命令行與shell腳本編程大全 第3版》Linux命令行--- Linux命令行與she…

徹底搞懂 JS 中 this 機制

徹底搞懂 JS 中 this 機制 摘要:本文屬于原創,歡迎轉載,轉載請保留出處:https://github.com/jasonGeng88/blog 目錄 this 是什么this 的四種綁定規則綁定規則的優先級綁定例外擴展:箭頭函數this 是什么 理解this之前&a…

?如何在2分鐘內將GraphQL服務器添加到RESTful Express.js API

You can get a lot done in 2 minutes, like microwaving popcorn, sending a text message, eating a cupcake, and hooking up a GraphQL server.您可以在2分鐘內完成很多工作,例如微波爐爆米花,發送短信, 吃蛋糕以及連接GraphQL服務器 。 …

leetcode 1744. 你能在你最喜歡的那天吃到你最喜歡的糖果嗎?

給你一個下標從 0 開始的正整數數組 candiesCount ,其中 candiesCount[i] 表示你擁有的第 i 類糖果的數目。同時給你一個二維數組 queries ,其中 queries[i] [favoriteTypei, favoriteDayi, dailyCapi] 。 你按照如下規則進行一場游戲: 你…

回歸分析_回歸

回歸分析Machine learning algorithms are not your regular algorithms that we may be used to because they are often described by a combination of some complex statistics and mathematics. Since it is very important to understand the background of any algorith…

ruby nil_Ruby中的數據類型-True,False和Nil用示例解釋

ruby niltrue, false, and nil are special built-in data types in Ruby. Each of these keywords evaluates to an object that is the sole instance of its respective class.true , false和nil是Ruby中的特殊內置數據類型。 這些關鍵字中的每一個都求值為一個對…

淺嘗flutter中的動畫(淡入淡出)

在移動端開發中,經常會有一些動畫交互,比如淡入淡出,效果如圖: 因為官方封裝好了AnimatedOpacity Widget,開箱即用,所以我們用起來很方便,代碼量很少,做少量配置即可,所以&#xff0…

數據科學還是計算機科學_何時不使用數據科學

數據科學還是計算機科學意見 (Opinion) 目錄 (Table of Contents) Introduction 介紹 Examples 例子 When You Should Use Data Science 什么時候應該使用數據科學 Summary 摘要 介紹 (Introduction) Both Data Science and Machine Learning are useful fields that apply sev…

空間復雜度 用什么符號表示_什么是大O符號解釋:時空復雜性

空間復雜度 用什么符號表示Do you really understand Big O? If so, then this will refresh your understanding before an interview. If not, don’t worry — come and join us for some endeavors in computer science.您真的了解Big O嗎? 如果是這樣&#xf…

leetcode 523. 連續的子數組和

給你一個整數數組 nums 和一個整數 k ,編寫一個函數來判斷該數組是否含有同時滿足下述條件的連續子數組: 子數組大小 至少為 2 ,且 子數組元素總和為 k 的倍數。 如果存在,返回 true ;否則,返回 false 。 …

Docker學習筆記 - Docker Compose

一、概念 Docker Compose 用于定義運行使用多個容器的應用,可以一條命令啟動應用(多個容器)。 使用Docker Compose 的步驟: 定義容器 Dockerfile定義應用的各個服務 docker-compose.yml啟動應用 docker-compose up二、安裝 Note t…

創建shell腳本

1.寫一個腳本 a) 用touch命令創建一個文件:touch my_script b) 用vim編輯器打開my_script文件:vi my_script c) 用vim編輯器編輯my_script文件,內容如下: #!/bin/bash 告訴shell使用什么程序解釋腳本 #My first script l…

線性回歸算法數學原理_線性回歸算法-非數學家的高級數學

線性回歸算法數學原理內部AI (Inside AI) Linear regression is one of the most popular algorithms used in different fields well before the advent of computers. Today with the powerful computers, we can solve multi-dimensional linear regression which was not p…

您應該在2020年首先學習哪種編程語言? ????d???s????:???su?

Most people’s journey toward learning to program starts with a single late-night Google search.大多數人學習編程的旅程都是從一個深夜Google搜索開始的。 Usually it’s something like “Learn ______”通常它類似于“學習______” But how do they decide which la…