matplotlib.pyplot.gci()函数
Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Pyplot是一个基于状态的Matplotlib模块接口,该模块提供了一个类似matlab的接口。Pyplot中可以使用的绘图有直线图、轮廓图、直方图、散点图、三维图等。
matplotlib.pyplot.gci()方法
使用matplotlib库pyplot模块中的gci()方法获取当前可着色的artist。
语法:matplotlib.pyplot.gci ()
参数:此方法不接受任何参数。
返回:该方法返回当前可着色的artist。
下面的例子演示了matplotlib.pyplot.gci()函数在matplotlib.pyplot中的作用:
示例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