Rub*_*ert 4 matplotlib python-import python-2.7
我正在尝试创建自己的matplotlib样式表,但Python没有检测到它们.更糟糕的是:当我移动五个默认样式表中的一个(ggplot.mplstyle)时,Python继续报告它是可用的.
我试图重新加载整个模块,但无济于事:
import matplotlib
reload(matplotlib)
from matplotlib import style as style
plt = matplotlib.pyplot
print plt.style.available
Run Code Online (Sandbox Code Playgroud)
只是一直回来
[u'dark_background', u'bmh', u'grayscale', u'ggplot', u'fivethirtyeight']
Run Code Online (Sandbox Code Playgroud)
如何强制"刷新"这些样式?
Ps我不是Python专家.
万一其他人偶然发现这篇文章,这个问题在这里得到报告和解决:
https://github.com/matplotlib/matplotlib/issues/3601
基本上,样式库在matplotlib config目录的子目录中查找文件.在linux/osx系统上,这就像是~/.matplotlib/stylelib/<my-custom-style>.mplstyle.
另外,正如@tcaswell在评论中建议的那样,加载是在导入时完成的,因此导入后添加或编辑的样式文件将无法在没有调用的情况下工作plt.style.reload_library().