Jupyter notebooks crashing on multiple plotly plots
Here is my code:
features = ['energy','loudness','speechiness','acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo','duration_ms']
plots = {}
for cols in features:
plots[cols] = px.scatter(genre, x =cols, y = 'danceability' , color = 'Genre', log_x=False,size_max=35)
for key in plots:
plots[key].show()
Is there a way I can clear the memory each time and save it . Then, hopefully close the plots. I tried savefig but that does not work.
Jupyter notebooks keeps on crashing.
I think storing all of your plotly.express figures in your plots
dictionary is causing the Jupyter notebook to run out of memory. If you're okay with saving the plots instead of rendering them in your notebook, you can save them locally on each iteration of the loop.
For example:
features = ['energy','loudness','speechiness','acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo','duration_ms']
for cols in features:
fig = px.scatter(genre, x =cols, y = 'danceability' , color = 'Genre', log_x=False,size_max=35)
fig.write_html(f"./plot_{cols}.html")