Python unable to locate mplstyle file in config folder

Question:

I want to add my custom.mplstyle to matplotlib. However,

mpl.get_configdir()

returns

/home/user/.config/matplotlib

In this folder I put the file

custom.mplstyle

However, when running Python I get

import matplotlib.pyplot as plt
plt.style.available
['Solarize_Light2', '_classic_test_patch', 'bmh', 'classic', 'dark_background',
 'fast', ..., 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'tableau-lorblind10']

but not

'custom'

When running

plt.style.use('custom')

I get

FileNotFoundError: [Errno 2] No such file or directory: 'custom'
Asked By: Mike

||

Answers:

If you are specifying a file, you need to give the whole path (absolute or relative) and name. E.g.

plt.style.use('../custom.mplstyle')

In the config folder it is in the stylelib subfolder. E.g.

/home/user/.config/matplotlib/stylelib
Answered By: Tim Roberts
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.