Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口。可在Pyplot中使用的各种图线图,轮廓图,直方图,散点图,3D图等。
matplotlib.pyplot.get_figlabels()方法
matplotlib库的pyplot模块中的get_figlabels()方法用于获取现有图形标签的列表。
用法:matplotlib.pyplot.get_figlabels()
参数:此方法不接受任何参数。
返回:此方法返回现有图形标签的列表。
以下示例说明了matplotlib.pyplot中的matplotlib.pyplot.get_figlabels()函数:
范例1:
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.01, 5.0, 0.01)
s = np.exp(-t)
plt.plot(t, s)
plt.ylim(1, 0)
plt.ylabel('Display Y-axis Label', fontweight ='bold')
plt.grid(True)
w = plt.get_figlabels()
plt.text(1.5, 0.58,
"List of existing figure labels:\n"
+ str(w),
fontsize = 12)
plt.title('matplotlib.pyplot.get_figlabels() function\
Example', fontweight ="bold")
plt.show()
输出:
范例2:
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.patches as patches
import numpy as np
mpl.rcParams['figure.dpi'] = 80
mpl.rcParams['savefig.dpi'] = 80
def redraw(event):
if np.size(plt.get_figlabels()):
ax.clear()
drawRectangles(ax)
fig.canvas.draw()
else:
pass
def drawRectangles(ax):
td2dis = ax.transData
coords = td2dis.transform([0.2, 0.5])
tr = mpl.transforms.Affine2D().rotate_deg_around(coords[0],
coords[1], 10)
t = td2dis + tr
rec0 = patches.Rectangle((0.5, 0.5),
0.25, 0.2,
color = 'green',
alpha = 0.4)
ax.add_patch(rec0)
rect1 = patches.Rectangle((0.5, 0.5),
0.25, 0.2,
color = 'green',
alpha = 0.7,
transform = t)
ax.add_patch(rect1);
plt.title('matplotlib.pyplot.get_figlabels() function Example', fontweight ="bold")
plt.grid()
figSize = (8, 6)
fig = plt.figure("Patch rotate", figsize = figSize)
ax = fig.add_subplot(111)
ax.set_xlim(0, 1);ax.set_ylim(0, 1);
fig.canvas.mpl_connect('resize_event', redraw)
drawRectangles(ax)
plt.show()
输出:
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.pyplot.get_figlabels() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。