日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/11/29 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matplotlib布局_Matplotlib多列,行跨度布局 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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).

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

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期間,我們可能會(huì)遇到一些情況,在這些情況下,我們希望將一組相關(guān)的圖顯示為大圖的一部分,以推動(dòng)我們的洞察力。 matplotlib的subplot功能為我們完成了工作。 但是,在某些情況下,我們可能希望合并多個(gè)子圖,并希望每個(gè)子圖具有不同的縱橫比。 我們?nèi)绾尾拍軐?shí)現(xiàn)這種布局,在此布局中,實(shí)際上有些子圖跨越了整個(gè)圖形的幾行/幾列?

Enter gridspec submodule of Matplotlib.

輸入gridspec子模塊。

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.

首先,我們需要?jiǎng)?chuàng)建一個(gè)GridSpec實(shí)例,該實(shí)例允許我們指定行和列的總數(shù)作為整體圖形中的參數(shù)以及figure對(duì)象。

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實(shí)例存儲(chǔ)在名為gs的變量中,并指定我們希望在整個(gè)圖中有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.

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

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.

我們?yōu)閳D形添加一個(gè)整體標(biāo)題,并刪除刻度線以更好地顯示布局,因?yàn)榇颂幍哪康氖茄菔救绾螌?shí)現(xiàn)跨越多行/列的子圖。 當(dāng)您實(shí)現(xiàn)此功能時(shí),顯然您會(huì)希望從數(shù)據(jù)框中添加軸刻度,標(biāo)簽等,并調(diào)整間距和圖形大小以容納這些繪圖元素。

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.

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

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程序包就可以輕松地實(shí)現(xiàn)上述目標(biāo),而只需要+和/運(yùn)算符和( )甚至嵌套嵌套的子圖就可以了。 單擊下面的鏈接,查看如何在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.

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

Would love to hear your feedback and comments. Thanks!

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

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

matplotlib布局

總結(jié)

以上是生活随笔為你收集整理的matplotlib布局_Matplotlib多列,行跨度布局的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。