在 Matplotlib 中靈活配置子圖大小
創建不同大小的子圖是可視化資料時的常見要求。 Matplotlib 提供了兩種調整子圖尺寸的方法:使用 GridSpec 或配置圖形本身。
使用Matplotlib 的圖形調整子圖大小
在提供的範例中,任務是建立兩個子圖,第一個子圖比第二個子圖寬三倍。使用圖窗的建構函數,可以使用 Figsize 參數調整第一個圖的大小。但是,第二張圖的大小無法透過這種方式直接控制。
有關鍵字參數的解(Matplotlib >= 3.6.0)
自Matplotlib 版本起3.6.0,關鍵字參數可以直接傳遞給plt .subplots 和subplot_mosaic 來指定width_ratios 或子圖的height_ratios。這消除了針對此特定任務對 GridSpec 的需求。
import matplotlib.pyplot as plt # Create subplots with custom width ratios f, (a0, a1) = plt.subplots(1, 2, width_ratios=[3, 1]) # Plot on subplots a0.plot(x, y) a1.plot(y, x) # Save to PDF f.savefig('custom_width_subplots.pdf')
將子圖與Gridspec_kw 一起使用
對於Matplotlib 的早期版本,或者進行更細粒度的控制子圖佈局,可以使用帶有gridspec_kw參數的subplots 函數。此方法涉及建立圖形和單獨的子圖,並使用 gridspec_kw 字典中的 width_ratios 或 height_ratios 指定。
import numpy as np import matplotlib.pyplot as plt # Generate data x = np.arange(0, 10, 0.2) y = np.sin(x) # Create subplots with custom width ratios f, (a0, a1) = plt.subplots(1, 2, gridspec_kw={'width_ratios': [3, 1]}) # Plot on subplots a0.plot(x, y) a1.plot(y, x) # Tighten layout and save to PDF f.tight_layout() f.savefig('grid_figure.pdf')
以上是如何建立尺寸靈活配置的 Matplotlib 子圖?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concatenateListSinpythonWithTheSamelements,使用:1)operatoTotakeEpduplicates,2)asettoremavelemavphicates,or3)listcompreanspherensionforcontroloverduplicates,每個methodhasdhasdifferentperferentperferentperforentperforentperforentperfornceandordorimplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允許ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver CS6
視覺化網頁開發工具