Clearing a subplot in Matplotlib

  • ax.clear() clears the axes. That is, it removes all settings and data from the axes such that you are left with an axes, just as it had been just created.

  • ax.axis("off") turns the axes off, such that all axes spines and ticklabels are hidden.

  • ax.set_visible(False) turns the complete axes invisible, including the data that is in it.

  • ax.remove() removes the axes from the figure.

Complete example:

import matplotlib.pyplot as plt

fig,axes = plt.subplots(2,3)
for ax in axes.flat:
    ax.plot([2,3,1])

axes[0,1].clear()
axes[1,0].axis("off")
axes[1,1].set_visible(False)
axes[0,2].remove()

plt.show()

enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)