spyder matplotlib 用户警告:此调用 matplotlib.use() 无效,因为后端已被选择
我正在尝试写一段代码来创建一个图形,但为了能在我想要的电脑上运行(学校的那台),我不能使用x-window这个后端来创建图形。我试着切换后端(在我的代码里有matplotlib.use('Agg')这行),但是每次创建图形时,它都会给我三个颜色条,而我只想要一个。它还给了我一个错误
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 *
有没有什么想法或者帮助?
1 个回答
8
回复晚了,但我想把这个记录下来,方便其他人参考。
你可能是在用Spyder作为你的Python界面。当你启动Spyder时,它会自动加载那些模块,所以你会看到关于已经选择过的错误信息。这里有个链接可以解释这个问题: https://groups.google.com/forum/#!topic/spyderlib/tRwgqEAIyvs