I'm trying to save pyplot figures using matplotlib pyplot.savefig in a Jupyter notebook. This works for png files but as of today, this no longer works for pdf and svg. Before today I regularly saved figures as pdf and svg. I'm running python3.6 in anaconda3 and I just updated today with conda update conda
and conda update --all
. Not sure whether or how an update might have broken the savefig function.
Executed command:
plt.savefig(filename, bbox_inches='tight', format='svg')
Full error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-149-9adcbb84294a> in <module>
28
29 filename = 'fig.svg'
---> 30 plt.savefig(filename, format='svg') #
31
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in _get_output_canvas(self, fmt)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in get_registered_canvas_class(format)
~/anaconda3/lib/python3.6/importlib/__init__.py in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
127
128
~/anaconda3/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)
~/anaconda3/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)
~/anaconda3/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'matplotlib.backends.backend_svg'
Modules imported:
import numpy as np
import scipy.integrate
import scipy.signal
import scipy.stats as st
import matplotlib.pyplot as plt
import seaborn as sns
# Set matplotlib rc params.
rc = {'lines.linewidth' : 2, 'axes.labelsize' : 20, 'legend.fontsize': 12, 'axes.titlesize' : 25, 'xtick.labelsize': 15, 'ytick.labelsize': 15} sns.set(rc=rc) sns.set_style("whitegrid")
%matplotlib inline