【发布时间】:2017-05-22 09:03:51
【问题描述】:
目标
- 使用 Matplotlib 绘制德克萨斯州
代码
import pandas as pd
import numpy as np
matplotlib.use('QT4Agg')
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import Normalize
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135,
resolution = 'h', area_thresh = 0.1,
llcrnrlon=-106.65, llcrnrlat=25.83,
urcrnrlon=-93.50, urcrnrlat=36.50)
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.fillcontinents(color = 'white')
map.drawmapboundary()
plt.show(block = False)
输出
调试
显然是changing backend helps,但是
matplotlib.use('QT4Agg')产生以下错误"Gtk* backend requires pygtk to be installed"在网上找了解决办法,听说你必须安装PyGTK,但是,安装时,我收到以下错误:
Building PyGTK using distutils is only supported on windows.(输入pip install PyGTK后)此外,尽管调用了
matplotlib.use('QT4Agg'),但我收到了错误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.。
问题
- 无法正确安装防止 matplotlib 在连续循环中运行所必需的软件包。我在这里错过了什么吗?有解决方法吗?
- 为什么,尽管在导入 matplotlib 之前调用了
matplotlib('QT4Agg'),但我收到了上面列出的错误(要点 #3)?
【问题讨论】:
-
github.com/matplotlib/matplotlib/pull/4779/files 可能会澄清这里发生了什么。
标签: python matplotlib plot pygtk