Open In App

Matplotlib.pyplot.cla() in Python

Last Updated : 19 Apr, 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.cla() Function

The cla() function in pyplot module of matplotlib library is used to clear the current axes.
Syntax:

matplotlib.pyplot.cla()

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

Example 1:




# Implementation of matplotlib function   
import matplotlib.pyplot as plt 
     
plt.plot([1, 2, 3, 4], [16, 4, 1, 8])
  
plt.cla()
plt.title('matplotlib.pyplot.cla Example')
plt.show()


Output:

Example 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)
   
ax.set_ylabel('y-axis')
ax.plot(t, s)
ax.grid(True)
  
ax1.set_ylabel('y-axis')
ax1.set_xlabel('x-axis')
ax1.plot(t, s)
ax1.grid(True)
ax1.cla()
  
fig.suptitle('matplotlib.pyplot.cla Example')
plt.show()


Output:



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

Similar Reads