📌  相关文章
📜  Python中的 Matplotlib.axes.Axes.set_adjustable()

📅  最后修改于: 2022-05-13 01:54:44.047000             🧑  作者: Mango

Python中的 Matplotlib.axes.Axes.set_adjustable()

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

matplotlib.axes.Axes.set_adjustable()函数

matplotlib 库的轴模块中的Axes.set_adjustable()函数用于定义轴将更改哪个参数以实现给定的方面。

下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.set_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("adjustable = box")
  
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("adjustable = datalim")
  
fig.suptitle('matplotlib.axes.Axes.set_adjustable() \
function Example\n', fontweight ="bold")
fig.canvas.draw()
plt.show()

输出:

示例 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("adjustable = box")
   
ax1.set_aspect('equal')
ax1.set_adjustable("datalim")
ax1.triplot(triang, 'bo-', lw = 1, color = "green")
ax1.set_title("adjustable = datalim")
   
fig.suptitle('matplotlib.axes.Axes.set_adjustable() \
function Example\n', fontweight ="bold")
fig.canvas.draw()
plt.show()

输出: