HomeLanguagesMatplotlib.figure.Figure.savefig() in Python

Matplotlib.figure.Figure.savefig() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.

matplotlib.figure.Figure.savefig() method

The savefig() method figure module of matplotlib library is used to save the current figure.

Syntax: savefig(self, fname, *, transparent=None, **kwargs)

Parameters: This method accept the following parameters that are discussed below:

  • fname :This parameter is the file name string.

Returns: This method does not returns any value.

Below examples illustrate the matplotlib.figure.Figure.savefig() function in matplotlib.figure:

Example 1:




# Implementation of matplotlib function  
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
   
fig, ax = plt.subplots()
s = ax.scatter([1, 2, 3], [4, 5, 6])
   
fig.savefig('scatter.svg')
  
fig.suptitle("""matplotlib.figure.Figure.savefig()
function Example\n\n""", fontweight ="bold") 
    
plt.show() 


Output:

python-matplotlib-savefig1

Example 2:




# Implementation of matplotlib function  
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
   
fig, ax = plt.subplots()
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
   
im = ax.imshow(Z,
               interpolation ='bilinear',
               cmap = cm.gray,
               origin ='lower',
               extent =[-3, 3, -3, 3])
   
fig.savefig('image.svg')
  
fig.suptitle("""matplotlib.figure.Figure.savefig()
function Example\n\n""", fontweight ="bold") 
    
plt.show() 


Output:

python-matplotlib-savefig

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32675 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7043 POSTS0 COMMENTS
Nicole Veronica
12182 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12277 POSTS0 COMMENTS
Shaida Kate Naidoo
7166 POSTS0 COMMENTS
Ted Musemwa
7436 POSTS0 COMMENTS
Thapelo Manthata
7140 POSTS0 COMMENTS
Umr Jansen
7133 POSTS0 COMMENTS