0

I'm using matplotlib animation package to create an animated graph.

I'm using celluloid package to simplify things, and so I can draw a seaborn plot.

I can't figure out why a little box is appearing in the saved video:

enter image description here

Here is my code:

#%%
sns.set()
plt.style.use('seaborn-pastel')
sns.set_style('white',
              {"axes.axisbelow": False,
               "font.sans-serif": ['Futura'],
               })
sns.set_context("paper", font_scale=1.5)


#%%
fig = plt.figure()
camera = Camera(fig)

for i in range(0, len(height_sample_data)+2, 2):
    plot1 = sns.scatterplot(x=0, y=height_sample_data.Height[:i],
                            hue=height_sample_data.col, alpha=0.75)
    sns.despine(bottom=True)
    plt.xticks([])
    plt.xlabel("")
    plt.ylabel("Height (cm)")
    plt.legend("", frameon=False)
    plt.text(-.1, 140, f"{i}/{len(height_sample_data)} DataPoints Plotted")
    plt.xlim(-0.5, 0.5)
    plt.ylim(130, 220)
    camera.snap()
anim = camera.animate(blit=True)
anim.save('Chapter6/Animations/AddingDots.mp4')

I ran almost the same plot (sans animation) and saved it to a png rather than MPEG, and the box was gone, so it seems to be something to do with the animation. I thought at first it was the legend outline, but I'm hiding that properly I think.

Edit: I'm on mac (Catalina) and using ffmpeg as mpeg saver, installed through homebrew.

Adam B
  • 3,662
  • 2
  • 24
  • 33

1 Answers1

0

I'm an idiot. It was in fact the legend. My original code to remove legend was meant to be used with the ax (axes) object. From plt, I needed to call

plt.legend("", frameon=False)

This gets rid of the frame that was causing the little square. The "" gets rid of contents, but not frame.

Adam B
  • 3,662
  • 2
  • 24
  • 33