Search code examples
pythonmatplotlibanimationimshow

Remove axis from animation.ArtistAnimation python


Here is a screenshot from an animations I have created in python:

enter image description here

I would like to remove the second axis that is being created. Here is my code:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.animation as animation
import matplotlib.image as mpimg
%matplotlib notebook

steps = np.arange(0,t_steps,5)
img = []
for k in steps:
    img.append(mpimg.imread(r'C:\Users\nikos.000\MHD1D\figures\jpg\test\_test%d.jpg'% k) ) #path file
                         
frames = [] # for storing the generated images
fig = plt.figure()
for i in range(len(img)):
    frames.append([plt.imshow(img[i], cmap=cm.Greys_r,animated=True, aspect='auto')])

ani = animation.ArtistAnimation(fig, frames, interval=50, blit=True,
                                repeat_delay=1000)
# ani.save('movie.mp4')
plt.show()

Solution

  •     fig = plt.figure("Animation")
    
        ax = fig.add_subplot(111)
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
    
        #append logic to ims
    
        ani = animation.ArtistAnimation(fig, ims)
    

    This should do the task.

    If you want to remove the bounding box too. Use:

        ax.axis('off')