Matplotlib-Fehler beheben: OSError: 'xkcd' not found in the style library

Problem:

Beim Versuch, den matplotlib xkcd-Style zu aktivieren mit

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

siehst du die folgende Fehlermeldung:

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

Lösung

Du kannst xkcd-Style-Plots nicht durch Ausführen von plt.style.use("xkcd") aktivieren. Verwende stattdessen with plt.xkcd():

xkcd_style_fix.py
with plt.xkcd():
    # TODO dein Plotting-Code kommt hier rein!
    # plt.plot(x, y) # Beispiel

Check out similar posts by category: Python