Matplotlib.axis.Axis.set_figure() function in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.

Matplotlib.axis.Axis.set_figure() Function

The Axis.set_figure() function in axis module of matplotlib library is used to set the Figure for this Axes. 
 

Syntax: Axis.set_figure(self, fig) 
 

Parameters: This method accepts the following parameters. 

  • fig: his parameter is the Figure instance.

Return value: This method does not return any value. 



Below examples illustrate the matplotlib.axis.Axis.set_figure() function in matplotlib.axis:
Example 1:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.lines as lines 
import matplotlib.transforms as mtransforms 
import matplotlib.text as mtext 
     
     
class GFGfun(lines.Line2D): 
    def __init__(self, *args, **kwargs): 
        self.text = mtext.Text(0, 0, '') 
        lines.Line2D.__init__(self, *args, **kwargs) 
        self.text.set_text(self.get_label()) 
     
    def set_figure(self, figure): 
        self.text.set_figure(figure) 
        lines.Line2D.set_figure(self, figure) 
     
    def set_axes(self, axes): 
        self.text.set_axes(axes) 
        lines.Line2D.set_axes(self, axes) 
     
    def set_transform(self, transform): 
        # 2 pixel offset 
        texttrans = transform + mtransforms.Affine2D().translate(2, 2
        self.text.set_transform(texttrans) 
        lines.Line2D.set_transform(self, transform) 
     
    def set_data(self, x, y): 
        if len(x): 
            self.text.set_position((x[-1], y[-1])) 
     
        lines.Line2D.set_data(self, x, y) 
     
    def draw(self, renderer): 
        lines.Line2D.draw(self, renderer) 
        self.text.draw(renderer) 
     
     
np.random.seed(10**7
     
     
fig, ax = plt.subplots() 
x, y = np.random.rand(2, 10
line = GFGfun(x, y, mfc ='green'
              ms = 12,  
              label ='Set_Figure'
     
line.text.set_color('green'
line.text.set_fontsize(16
     
ax.add_line(line)
  
fig.suptitle('matplotlib.axis.Axis.set_figure() \
function Example\n', fontweight ="bold")  
    
plt.show() 

chevron_right


Output: 
 

Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.lines as lines 
import matplotlib.transforms as mtransforms 
import matplotlib.text as mtext 
     
     
class GFGfun(lines.Line2D): 
    def __init__(self, *args, **kwargs): 
        self.text = mtext.Text(0, 0, '') 
        lines.Line2D.__init__(self, *args, **kwargs) 
        self.text.set_text(self.get_label()) 
     
    def set_figure(self, figure): 
        self.text.set_figure(figure) 
        lines.Line2D.set_figure(self, figure) 
     
     
np.random.seed(10**7
     
     
fig, ax = plt.subplots() 
x, y = np.random.rand(2, 30
line = GFGfun(x, y, mfc ='green'
              ms = 12
              label ='Label'
     
line.text.set_color('green'
line.text.set_fontsize(16
     
ax.add_line(line) 
  
fig.suptitle('matplotlib.axis.Axis.set_figure() \
function Example\n', fontweight ="bold")  
    
plt.show() 

chevron_right


Output: 


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.




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.