Jupyter 笔记本 + Matplotlib;冻结 plot.show()
Jupyter Notebook + Matplotlib; Freeze on plot.show()
OBJECTIVE
- 使用 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)?
这是在 Jupyter Notebook 中还是类似的东西?通常你不应该做
matplotlib.use('QT4Agg')
import matplotlib
按照这个顺序,因为 matplotlib 不在命名空间中。更改顺序,然后重新启动 Jupyter 内核或将所有这些转储到 .py 文件中。
在 Jupyter 中,您应该可以调用
%matplotlib qt4
在导入 matplotlib 之前设置后端而不是调用 use().
OBJECTIVE
- 使用 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)?
这是在 Jupyter Notebook 中还是类似的东西?通常你不应该做
matplotlib.use('QT4Agg')
import matplotlib
按照这个顺序,因为 matplotlib 不在命名空间中。更改顺序,然后重新启动 Jupyter 内核或将所有这些转储到 .py 文件中。
在 Jupyter 中,您应该可以调用
%matplotlib qt4
在导入 matplotlib 之前设置后端而不是调用 use().