Matplotlib.figure.Figure.clear() en Python

Matplotlib es una biblioteca en Python y es una extensión matemática numérica para la biblioteca NumPy. El módulo de figura proporciona el artista de nivel superior, la figura, que contiene todos los elementos de la trama. Este módulo se utiliza para controlar el espaciado predeterminado de las subparcelas y el contenedor de nivel superior para todos los elementos de la parcela.

función matplotlib.figure.Figure.clear()

El módulo de figura del método clear() de la biblioteca matplotlib se utiliza para borrar la figura.

Sintaxis: clear(self, keep_observers=False)

Parámetros: Este acepta los siguientes parámetros que se describen a continuación:

  • keep_observers: este parámetro es el valor booleano.

Devoluciones: este método no devuelve ningún valor.

Los siguientes ejemplos ilustran la función matplotlib.figure.Figure.clear() en matplotlib.figure:

Ejemplo 1:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
      
fig, ax = plt.subplots()
  
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
  
ax.plot([1, 2, 3])
ax.grid(True)
  
fig.clear(True)
   
fig.suptitle('matplotlib.figure.Figure.clear() \
function Example\n\n', fontweight ="bold")
  
plt.show()

Producción:

Ejemplo 2:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
      
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)
   
fig, [ax, ax1] = plt.subplots(2, 1, 
                              sharex = True)
   
ax.set_ylabel('y-axis')
ax.plot(t, s)
ax.grid(True)
ax.set_title('Sample Example',
             fontsize = 12,
             fontweight ='bold')
   
ax1.set_ylabel('y-axis')
ax1.plot(t, s)
ax1.grid(True)
  
fig.clear(False)
   
fig.suptitle('matplotlib.figure.Figure.clear() \
function Example\n\n', fontweight ="bold")
  
plt.show()

Producción:

Publicación traducida automáticamente

Artículo escrito por SHUBHAMSINGH10 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *