If the file doesn’t exist, you can create it and add the above lines.
3. Alternative: Use a Startup Script
If you don’t want to edit the configuration file, you can create a startup script to set the matplotlib backend for all notebooks:
Navigate to your IPython profile directory:
bash
jupyter --config-dir
This will show you the location of your Jupyter config directory.
Go to the startup folder inside the profile directory (e.g., ~/.ipython/profile_default/startup/). If the startup folder doesn’t exist, create it.
Create a new Python file, e.g., 00-matplotlib-widget.py, and add the following line:
python
%matplotlib widget
Save the file. Now, every time you start a Jupyter notebook, the %matplotlib widget magic command will be executed automatically.
4. Restart Jupyter
After making these changes, restart your Jupyter notebook server for the changes to take effect.
Note: If you’re using JupyterLab, ensure that the @jupyter-widgets/jupyterlab-manager extension is installed, as it’s required for the widget backend to work. You can install it with: