python制作词云时出现figure1 figure2_Python Matplotlib.figure.Figure.subplots_adjust()用法及代码示例...

本文介绍了Python的Matplotlib库中用于调整子图间距的subplots_adjust()方法,包括其参数含义和使用示例。示例1展示了基本的子图调整,而示例2结合了交互式功能,通过TextBox实现公式输入并动态更新图形。
摘要由CSDN通过智能技术生成

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Figure模块提供了顶层Artist,即Figure,其中包含所有绘图元素。此模块用于控制所有图元的子图和顶层容器的默认间距。

matplotlib.figure.Figure.subplots_adjust()方法

matplotlib库的subplots_adjust()方法图形模块用于用kwarg更新SubplotParams。

用法:subplots_adjust(self, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)

参数:此方法接受下面讨论的以下参数:

left:此参数是该图子图的左侧。

right:此参数是该图子图的右侧。

bottom:此参数是该图子图的底部。

top:此参数是该图子图的顶部。

wspace:此参数是为子图之间的空间保留的宽度量,表示为平均轴宽度的一部分。

hspace:此参数是为子图之间的空间保留的高度量,表示为平均轴高度的一部分。

返回值:此方法不返回任何值。

以下示例说明了matplotlib.figure中的matplotlib.figure.Figure.subplots_adjust()函数:

范例1:

# Implementation of matplotlib function

import numpy as np

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]

y = [1, 4, 9, 16]

fig = plt.figure()

axs = fig.subplots()

axs.plot(x, y)

fig.subplots_adjust(bottom = 0.15)

fig.suptitle("""matplotlib.figure.Figure.subplots_adjust()

function Example\n\n""", fontweight ="bold")

fig.show()

输出:

范例2:

# Implementation of matplotlib function

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.widgets import TextBox

fig, ax = plt.subplots()

fig.subplots_adjust(bottom = 0.2)

t = np.arange(-2.0, 2.0, 0.001)

s = np.sin(t)+np.cos(2 * t)

initial_text = "sin(t) + cos(2t)"

l, = ax.plot(t, s, lw = 2)

def submit(text):

ydata = eval(text)

l.set_ydata(ydata)

ax.set_ylim(np.min(ydata), np.max(ydata))

plt.draw()

axbox = plt.axes([0.4, 0.05, 0.3, 0.075])

text_box = TextBox(axbox, 'Formula Used:',

initial = initial_text)

text_box.on_submit(submit)

fig.suptitle("""matplotlib.figure.Figure.subplots_adjust()

function Example\n\n""", fontweight ="bold")

fig.show()

输出:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值