0

I tried to render several hundred images with python and matplotlib using the following code:

def render_state(np_data_array):
    filename = "render/fig_" + str(i) + ".png"

    fig = plt.figure(figsize = (12,12) )
    aa = fig.add_subplot(111)
    aa.imshow(np_data_array,cmap='gray')

    fig.savefig(filename)

unfortunately matplotlib is also rendering everything into the jupyter notebook. Is there a way to prevent any output from matplotlib? I couldn't really find a way and most answers on the internet just say to not use plt.show() what I don't even use

Tommy
  • 111
  • 6

2 Answers2

1

%%capture as the first line of the cell works like charm! Thanks to ImportanceOfBeingErnest

Tommy
  • 111
  • 6
0

You can also just use plt.close() at the end of your notebook cell like explained here. This way, you can still render other widgets like a tqdm progress bar. With %%capture, all widgets are blocked.

Ray Walker
  • 285
  • 3
  • 5