Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。
matplotlib.axes.Axes.indicate_inset_zoom()函數
matplotlib庫的軸模塊中的Axes.indicate_inset()函數還用於向軸添加插入指示器。
用法: Axes.indicate_inset(self, bounds, inset_ax=None, *, transform=None, facecolor=’none’, edgecolor=’0.5′, alpha=0.5, zorder=4.99, **kwargs)
參數:此方法接受以下描述的參數:
- inset_ax:此參數是用於繪製連接線的可選插入軸。
- **kwargs:其他kwarg傳遞給Axes.inset_rectangle。
返回值:此方法返回以下內容:
- rectangle_patch:這將返回指示器框架。
- connector_lines:這將返回連接到inset_ax的(lower_left,upper_left,lower_right upper_right)角的四根連接器線。
注意:此函數適用於Matplotlib版本> = 3.0
以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.indicate_inset_zoom()函數:
範例1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
Z2 = np.zeros([150, 150], dtype ="g")
axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47])
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
ax.indicate_inset_zoom(axins)
ax.set_title('matplotlib.axes.Axes.indicate_inset_zoom() Example',
fontsize = 14, fontweight ='bold')
plt.show()
輸出:
範例2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
def geeks():
from matplotlib.cbook import get_sample_data
import numpy as np
f = get_sample_data("axes_grid / bivariate_normal.npy",
asfileobj = False)
z = np.load(f)
return z, (-3, 4, -4, 3)
fig, ax = plt.subplots()
X, extent = geeks()
Z2 = np.zeros([150, 150], dtype ="g")
ny, nx = X.shape
Z2[30:30 + ny, 30:30 + nx] = X
ax.imshow(Z2, extent = extent, interpolation ="nearest",
origin ="lower", cmap ="YlGn")
axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47])
axins.imshow(Z2, extent = extent, interpolation ="nearest",
origin ="lower", cmap ="BuGn")
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
ax.indicate_inset_zoom(axins)
ax.set_title('matplotlib.axes.Axes.indicate_inset_zoom() Example',
fontsize = 14, fontweight ='bold')
plt.show()
輸出:
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.indicate_inset_zoom() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。