Python中的 Matplotlib.pyplot.gci()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是 Matplotlib 模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。
matplotlib.pyplot.gci() 方法
matplotlib 库的 pyplot 模块中的 gci () 方法用于获取当前可着色的艺术家。
Syntax: matplotlib.pyplot.gci()
Parameters: This method does not accept any parameters.
Returns: This method returns the current colorable artist.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.gci()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.close('all')
arr = np.arange(100).reshape((10, 10))
fig = plt.figure(figsize =(4, 4))
im = plt.imshow(arr,
interpolation ="none",
cmap ="plasma")
divider = make_axes_locatable(plt.gca())
cax = divider.append_axes("left",
"15 %",
pad ="30 %")
plt.colorbar(im, cax = cax)
print("The current colorable artist is :")
print(plt.gci())
fig.suptitle('matplotlib.pyplot.gci() function \
Example\n\n', fontweight ="bold")
plt.show()
输出:
The current colorable artist is :
AxesImage(50, 44;310x308)
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from scipy import sin, cos
fig, ax = plt.subplots(2, 1)
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y1 = sin(x)
y2 = cos(x)
plt.sca(ax[0])
plt.plot(x, y1)
plt.sca(ax[1])
plt.plot(x, y2)
print("The current colorable artist is :")
print(plt.gci())
fig.suptitle('matplotlib.pyplot.gci() function \
Example\n\n', fontweight ="bold")
plt.show()
输出:
The current colorable artist is :
None