python axes get_Python Matplotlib.axes.Axes.get_adjustable()用法及代码示例

本文介绍了Python中Matplotlib库的Axes.get_adjustable()函数,用于获取Axes的可调参数。示例展示了如何使用该函数并在不同场景下调整图表的可调性。
摘要由CSDN通过智能技术生成

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。

matplotlib.axes.Axes.get_adjustable()功能

matplotlib库的axiss模块中的Axes.get_adjustable()函数用于获取为实现给定方面而给定的Axes参数。

用法: Axes.get_adjustable(self)

参数:此方法不接受任何参数。

返回值:此方法返回可调值。

以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.get_adjustable()函数:

范例1:

# ImpleIn Reviewtation of matplotlib function

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2)

ax1.set_xscale("log")

ax1.set_yscale("log")

ax1.set_xlim(1e1, 1e3)

ax1.set_ylim(1e2, 1e3)

ax1.set_aspect(1)

ax1.set_title("Axes 1")

ax2.set_xscale("log")

ax2.set_yscale("log")

ax2.set_adjustable("datalim")

ax2.plot([1, 113, 10], [1, 119, 100], "o-")

ax2.set_xlim(1e-1, 1e2)

ax2.set_ylim(1e-1, 1e3)

ax2.set_aspect(1)

ax2.set_title("Axes 2")

w = ax1.get_adjustable()

w1 = ax2.get_adjustable()

ax1.text(20, 400,

"     Value return by\n get_adjustable():" +str(w))

ax2.text(1, 200,

"   Value return by \nget_adjustable():\n     " +str(w1))

fig.suptitle('matplotlib.axes.Axes.get_adjustable() function Example\n',

fontweight ="bold")

fig.canvas.draw()

plt.show()

输出:

557f76882e82f1ecd375b529b5918b96.png

范例2:

# ImpleIn Reviewtation of matplotlib function

import matplotlib.pyplot as plt

import matplotlib.tri as tri

import numpy as np

n_angles = 40

n_radii = 10

min_radius = 2

radii = np.linspace(min_radius, 0.95, n_radii)

angles = np.linspace(0, 4 * np.pi, n_angles,

endpoint = False)

angles = np.repeat(angles[..., np.newaxis],

n_radii, axis = 1)

angles[:, 1::2] += np.pi / n_angles

x = (radii * np.cos(angles)).flatten()

y = (radii * np.sin(angles)).flatten()

triang = tri.Triangulation(x, y)

triang.set_mask(np.hypot(x[triang.triangles].mean(axis = 1),

y[triang.triangles].mean(axis = 1))

< min_radius)

fig, (ax, ax1) = plt.subplots(1, 2)

ax.triplot(triang, 'bo-', lw = 1, color = "green")

ax.set_aspect('equal')

ax.set_title("Axes 1")

ax1.set_aspect('equal')

ax1.set_adjustable("datalim")

ax1.triplot(triang, 'bo-', lw = 1, color = "green")

ax1.set_title("Axes 2")

w = ax.get_adjustable()

w1 = ax1.get_adjustable()

ax.text(-1.15, -3.5,

"     Value return by\n get_adjustable():" +str(w))

ax1.text(-1, 2.5,

"   Value return by \nget_adjustable():\n     " +str(w1))

fig.suptitle('matplotlib.axes.Axes.get_adjustable() function \

Example\n', fontweight ="bold")

fig.canvas.draw()

plt.show()

输出:

e22126d6e17ca4b028ac56811949be4d.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值