To make matplotlib generate SVG figures instead of PNG by default in all your JupyterLab .ipynb notebooks, you need to set the default backend and save format in your matplotlib configuration. Here’s how you can do it:
Add the following lines at the beginning of your notebook (or in a cell you run first):
python%matplotlib inline import matplotlib.pyplot as plt # Set the default format to SVG plt.rcParams['savefig.format'] = 'svg' plt.rcParams['figure.facecolor'] = 'white' # Optional: ensures white background
%matplotlib inline ensures plots are displayed inline in JupyterLab.plt.rcParams['savefig.format'] = 'svg' sets the default save format to SVG.When you save a figure using plt.savefig(), it will now default to SVG:
pythonplt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('my_plot.svg') # Will save as SVG
If you want this setting to apply automatically to all your notebooks, you can add the configuration to your matplotlib config file:
~/.config/matplotlib/matplotlibrc (Linux/Mac) or C:\Users\<YourUsername>\.matplotlib\matplotlibrc (Windows).textsavefig.format: svg figure.facecolor: white
Run a simple plot and check the file type:
pythonplt.plot([1, 2, 3]) plt.savefig('test_plot') # Should save as test_plot.svg