跨图形共享 AxesSubplot 对象
在 matplotlib 中,通常使用 Figure.add_subplot() 方法创建 AxesSubplot 对象。但是,您可能希望将轴子图的创建与图形实例分离,以便在不同的图形中重用它们。
独立创建 AxesSubplot 对象
要实现这一点,您可以利用替代方法:
import matplotlib.pyplot as plt axes = plt.AxesSubplot(fig, 1, 1, 1) # Create an empty axes subplot axes.set_xlabel("X-Label") # Populate axes settings axes.set_ylabel("Y-Label")
这允许您创建 AxesSubplot 对象,而无需将其与特定图形关联起来。
将 AxesSubplot 对象添加到图形
独立创建轴子图后,可以使用以下方法将它们添加到图形中:
# Add axes to figure 1 fig1 = plt.figure() fig1.axes.append(axes) # Add axes to figure 2 fig2 = plt.figure() fig2.axes.append(axes)
重复使用轴子图
通过向多个图形添加轴子图,您可以方便地重复使用它们。例如,您可以定义一个函数来在指定轴子图上绘制数据:
def plot_on_axes(axes, data): axes.plot(data)
然后可以在各种图形中使用此函数在共享轴子图上绘制相同的数据。
调整轴的大小
将 AxesSubplot 对象从一个图形移动到另一个图形可能需要调整大小以匹配新人物的布局。要调整坐标区的大小,您可以使用 set_geometry() 方法:
axes.set_geometry(1, 2, 1) # Update axes geometry for figure 1, with two columns
示例
以下代码片段演示了如何独立创建和重用坐标区子图:
import matplotlib.pyplot as plt # Create independent axes subplots ax1 = plt.AxesSubplot(None, 1, 1, 1) ax2 = plt.AxesSubplot(None, 1, 1, 1) # Populate axes settings ax1.set_xlabel("X1") ax1.set_ylabel("Y1") ax2.set_xlabel("X2") ax2.set_ylabel("Y2") # Add axes subplots to figure 1 fig1 = plt.figure() fig1.axes.append(ax1) fig1.axes.append(ax2) # Add axes subplots to figure 2 fig2 = plt.figure() fig2.axes.append(ax1) plt.show()
此示例创建两个轴子图,将它们添加到两个不同的图形中,并显示他们。
以上是如何在 Matplotlib 中的不同图形中重用 AxesSubplot 对象?的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonuseshybridapprace,ComminingCompilationTobyTecoDeAndInterpretation.1)codeiscompiledtoplatform-Indepententbybytecode.2)bytecodeisisterpretedbybythepbybythepythonvirtualmachine,增强效率和通用性。

theKeyDifferencesBetnewpython's“ for”和“ for”和“ loopsare:1)” for“ loopsareIdealForiteringSequenceSquencesSorkNowniterations,而2)”,而“ loopsareBetterforConterContinuingUntilacTientInditionIntionismetismetistismetistwithOutpredefinedInedIterations.un

在Python中,可以通过多种方法连接列表并管理重复元素:1)使用 运算符或extend()方法可以保留所有重复元素;2)转换为集合再转回列表可以去除所有重复元素,但会丢失原有顺序;3)使用循环或列表推导式结合集合可以去除重复元素并保持原有顺序。

fasteStmethodMethodMethodConcatenationInpythondependersonListsize:1)forsmalllists,operatorseffited.2)forlargerlists,list.extend.extend()orlistComprechensionfaster,withextendEffaster,withExtendEffers,withextend()withextend()是extextend()asmoremory-ememory-emmoremory-emmoremory-emmodifyinginglistsin-place-place-place。

toInSerteLementIntoApythonList,useAppend()toaddtotheend,insert()foreSpificPosition,andextend()formultiplelements.1)useappend()foraddingsingleitemstotheend.2)useAddingsingLeitemStotheend.2)useeapecificindex,toadapecificindex,toadaSpecificIndex,toadaSpecificIndex,blyit'ssssssslorist.3 toaddextext.3

pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)他们areStoredIncoNtiguulMemoryBlocks,mayrequireRealLealLocationWhenAppendingItems,EmpactingPerformance.2)LinkesedlistSwoldOfferefeRefeRefeRefeRefficeInsertions/DeletionsButslowerIndexeDexedAccess,Lestpypytypypytypypytypy

pythonoffersFourmainMethodStoreMoveElement Fromalist:1)删除(值)emovesthefirstoccurrenceofavalue,2)pop(index)emovesanderturnsanelementataSpecifiedIndex,3)delstatementremoveselemsbybybyselementbybyindexorslicebybyindexorslice,and 4)

toresolvea“ dermissionded”错误Whenrunningascript,跟随台词:1)CheckAndAdjustTheScript'Spermissions ofchmod xmyscript.shtomakeitexecutable.2)nesureThEseRethEserethescriptistriptocriptibationalocatiforecationAdirectorywherewhereyOuhaveWritePerMissionsyOuhaveWritePermissionsyYouHaveWritePermissions,susteSyAsyOURHomeRecretectory。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

记事本++7.3.1
好用且免费的代码编辑器

禅工作室 13.0.1
功能强大的PHP集成开发环境