Open In App

Matplotlib.pyplot.get_figlabels() in Python

Last Updated : 10 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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')
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()


Output:

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()):
        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()


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads