Skip to content
Related Articles

Related Articles

Improve Article

Matplotlib.pyplot.get_figlabels() in Python

  • Last Updated : 10 May, 2020
Geek Week

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.

matplotlib.pyplot.get_figlabels() method

The get_figlabels() method in pyplot module of matplotlib library is used to get the list of existing figure labels.

Syntax: matplotlib.pyplot.get_figlabels()

Parameters: This method does not accept any parameters.

Returns: This method returns the list of existing figure labels.

Below examples illustrate the matplotlib.pyplot.get_figlabels() function in matplotlib.pyplot:

Example 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')
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"


Example 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()):
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)
    rect1 = patches.Rectangle((0.5, 0.5),
                              0.25, 0.2,
                              color = 'green',
                              alpha = 0.7,
                              transform = t)
    plt.title('matplotlib.pyplot.get_figlabels() function Example', fontweight ="bold")
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)


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :