所以我試圖編寫一段代碼來創建一個圖形,但爲了讓它在電腦,我想要它(學校之一),我不能使用X窗口後端來創建該數字。我嘗試切換後端使用(我在我的代碼中使用了matplotlib.use('Agg')語句),但是每當它創建圖形時,當我只需要一個圖形時,它就會給我3個顏色條。這也給我的錯誤spyder matplotlib UserWarning:對matplotlib.use()的調用沒有效果,因爲已經選擇了後端
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 *
任何意見或幫助?
你的實際繪圖代碼是什麼? – Ffisegydd
你的IDE中的某些東西是爲你導入pyplot的。 – tacaswell
,如果你正在編寫腳本,我強烈建議不要使用'pyplot'(改用OO接口),並且我會阻止你從'從pylab import *'中執行''。 – tacaswell