[英]Jupyter Notebook + Matplotlib; Freeze on plot.show()
目的
码
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)
OUTPUT
调试
显然改变后端有帮助 ,但是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.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('QT4Agg')
,却收到上面列出的错误(项目符号#3)? 这是在Jupyter Notebook中还是类似的东西? 通常你不应该做
matplotlib.use('QT4Agg')
import matplotlib
按照这个顺序,因为matplotlib不会在名称空间中。 更改顺序,然后重新启动Jupyter内核或将所有这些都转储到.py文件中。
在Jupyter中,您应该可以致电
%matplotlib qt4
在导入matplotlib设置后端之前,而不是调用use() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.