How to fix matplotlib OSError: 'xkcd' not found in the style library

Problem:

While trying to enable the matplotlib xkcd style using

xkcd_style_error.py
plt.style.use("xkcd")

you see the following error message:

xkcd_error.txt
OSError: 'xkcd' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles

Solution

You can’t enable xkcd-style plots by running plt.style.use("xkcd"). Instead, use with plt.xkcd():

xkcd_style_fix.py
with plt.xkcd():
    # TODO your plotting code goes here!
    # plt.plot(x, y) # Example

 


Check out similar posts by category: Python