警告信息通常很重要,我建议不要忽略。我在寻找使用 sphinx 构建文档的解决方案时发现了您的问题。我收到了类似的消息,以及警告的一些附加上下文:
UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was originally set to 'Qt5Agg' by the following code:
File "setup.py", line 131, in <module>
'psql' : ['psycopg2>=2.7.1'],
然后我在https://github.com/conchoecia/pauvre/issues/18找到了解决方案。导入顺序如下:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
在修复之前,我只对模块进行了以下导入
from mymod.utils import plotutils
import mymod.plots as plots
import matplotlib.pyplot as plt
我认为这个问题的导入顺序导致了警告消息。但是,我无法针对所提供的信息重新创建您的警告。如果能从该警告中再看到几行,那就太好了。
在与其他开发人员进行了更多讨论之后,很明显我的 pyplot 导入在文件中,而它属于我需要使用 plt.
了解渲染很重要,您可以在
https://matplotlib.org/faq/usage_faq.html#what-is-a-backend
和
https://matplotlib.org/api/matplotlib_configuration_api.html#matplotlib 获得更多信息。
请记住其他处理代码可能会更改或默认后端名称。