jjzjj

python - spyder matplotlib UserWarning : This call to matplotlib. use() 无效,因为已经选择了后端

coder 2023-08-21 原文

所以我正在尝试编写一段代码来创建图形,但是为了让它在我想要的计算机(学校计算机)上运行,我不能使用 x-window 后端来创建图形。我尝试切换后端使用(我的代码中有 matplotlib.use('Agg') 语句),但每当它创建图形时,当我只想要一个时,它会在图形上给我 3 个颜色条。它还给我错误

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.

warnings.warn(_use_error_msg)

我的代码是这样开始的:

import matplotlib
matplotlib.use('Agg')
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from pylab import *

有什么想法或帮助吗?

最佳答案

迟到的回复,但我想为其他人记录下来。

您可能正在使用 Spyder 作为您的 Python 界面。当您启动 Spyder 时,它会自动加载这些模块,因此会出现关于如何选择它的错误。这里有一个解释它的链接:https://groups.google.com/forum/#!topic/spyderlib/tRwgqEAIyvs

关于python - spyder matplotlib UserWarning : This call to matplotlib. use() 无效,因为已经选择了后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23452550/

有关python - spyder matplotlib UserWarning : This call to matplotlib. use() 无效,因为已经选择了后端的更多相关文章

随机推荐