我尝试安装jupyter,但不知何故,它无法与matplotlib一起使用3D图形。我总是遇到以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-1-dd74dfec8882> in <module>()
9
10 fig = plt.figure()
---> 11 ax = fig.gca(projection='3d')
12 X, Y, Z = axes3d.get_test_data(0.05)
13 ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in gca(self, **kwargs)
1272
1273 # no axes found, so create one which spans the figure
-> 1274 return self.add_subplot(1, 1, 1, **kwargs)
1275
1276 def sca(self, a):
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in add_subplot(self, *args, **kwargs)
962 self._axstack.remove(ax)
963
--> 964 a = subplot_class_factory(projection_class)(self, *args, **kwargs)
965
966 self._axstack.add(key, a)
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_subplots.pyc in __init__(self, fig, *args, **kwargs)
76
77 # _axes_class is set in the subplot_class_factory
---> 78 self._axes_class.__init__(self, fig, self.figbox, **kwargs)
79
80 def __reduce__(self):
/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.pyc in __init__(self, fig, rect, *args, **kwargs)
89 Axes.__init__(self, fig, rect,
90 frameon=True,
---> 91 *args, **kwargs)
92 # Disable drawing of axes by base class
93 Axes.set_axis_off(self)
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in __init__(self, fig, rect, axisbg, frameon, sharex, sharey, label, xscale, yscale, **kwargs)
435 self._hold = rcParams['axes.hold']
436 self._connected = {} # a dict from events to (id, func)
--> 437 self.cla()
438 # funcs used to format x and y - fall back on major formatters
439 self.fmt_xdata = None
/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.pyc in cla(self)
1043 self._zmargin = 0
1044
-> 1045 Axes.cla(self)
1046
1047 self.grid(rcParams['axes3d.grid'])
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in cla(self)
906 self.containers = []
907
--> 908 self.grid(self._gridOn, which=rcParams['axes.grid.which'])
909 props = font_manager.FontProperties(size=rcParams['axes.titlesize'],
910 weight=rcParams['axes.titleweight'])
/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.pyc in grid(self, b, **kwargs)
1254 if len(kwargs) :
1255 b = True
-> 1256 self._draw_grid = maxes._string_to_bool(b)
1257
1258 def ticklabel_format(self, **kwargs) :
AttributeError: 'module' object has no attribute '_string_to_bool'
在我安装Jupyter之前没有发生这种情况,所以我认为删除Jupyter会有所帮助。我跑了
pip uninstall jupyter
并删除主目录中的.ipython
和.jupyter
中的目录,但每当我运行时
ipython notebook
Jupyter布局仍然存在,我仍然遇到同样的错误...我甚至尝试再次卸载并安装ipython
和ipython-notebook
,但它仍然无效。
有什么建议吗?我对内核并不太了解......
非常感谢。
答案 0 :(得分:0)
似乎是matplotlib
的apt包的问题。完成apt-get purge matplotlib
和apt-get autoremove matplotlib
后,pip install matplotlib
后,它就可以了。
谢谢,
答案 1 :(得分:0)
如果您使用的是Aniponda安装的Scipy,则可以使用conda update matplotlib
。这导致我更新python,matplotlib,numpy和其他一些软件包。然后Matplotlib可以导入并正常工作。我不必以这种方式卸载任何东西。 Jupyter继续工作。
答案 2 :(得分:0)
跑完之后 点击卸载jupyter和 删除主目录中.ipython和.jupyter中的目录 运行
jupyter --path
然后删除路径上的所有内容
小心删除python安装目录中的脚本 {仅删除jupyter文件}
最后你将没有jupyter