seismo-live / seismo_live

Live Jupyter Notebooks for Seismology
http://seismo-live.org
78 stars 73 forks source link

update many notebooks that they they work with python3.10 and the latest jupyterlab #42

Open Thomas-Ulrich opened 4 years ago

Thomas-Ulrich commented 4 years ago

In commit 41f4d2b, I changed backend to widget and fix the interactive plots using this script:

find . -name "*.py" -exec sed -i 's/plt.gcf().canvas.draw()/plt.gcf().canvas.draw(); display(plt.gcf()); clear_output(wait=True)/g' {} \;
find . -name "*.py" -exec sed -i 's/fig.canvas.draw()/fig.canvas.draw(); display(fig); clear_output(wait=True)/g' {} \;
find . -name "*.py" -exec sed -i 's/fig2.canvas.draw()/fig2.canvas.draw(); display(fig2); clear_output(wait=True)/g' {} \;
find . -name "*.py" -exec sed -i "/^[^#]/ s/plt.switch_backend(\"nbagg\")/%matplotlib widget\nfrom IPython.display import display, clear_output/g" {} \;
find . -name "*.py" -exec sed -i "/^[^#]/ s/plt.switch_backend(\"TkAgg\")/%matplotlib widget\nfrom IPython.display import display, clear_output/g" {} \;
find . -name "*.py" -exec sed -i 's/matplotlib.use(\"nbagg\")/%matplotlib widget\nfrom IPython.display import display, clear_output/g' {} \;

(some files need to be fixed manually, e.g. fd_ac2d_heterogeneous_solution.py)

I also removed plt.ion and ioff systematically with:

find . -name "*.py" -exec sed -i '/plt.ion()/d' {} \;
find . -name "*.py" -exec sed -i '/plt.ioff()/d' {} \;

(avoiding Kernel does not exist warnings).

megies commented 1 month ago

CC @christadler

Thomas-Ulrich commented 1 month ago

Let's wait for the semester to be finished to possibly merge this one (as I'm adding new changes every time I'm discovering new notebooks while teaching).