I'm trying to use mplot3d to plot something 3D. I have Mac OSX. However I get this error:
ax = fig.gca(projection = '3d')
File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1368, in gca
return self.add_subplot(1, 1, 1, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1020, in add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_subplots.py", line 73, in __init__
self._axes_class.__init__(self, fig, self.figbox, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 91, in __init__
*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 551, in __init__
self.cla()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 1045, in cla
Axes.cla(self)
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 1062, in cla
self.grid(False) # Disable grid on init to use rcParameter
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 1256, in grid
self._draw_grid = maxes._string_to_bool(b)
AttributeError: 'module' object has no attribute '_string_to_bool'
I searched this problem here and tried a bunch of solutions. I am using matplotlib 2.0.0:
- removing mplot3d (located in /usr/local/lib/python2.7/site-packages/mpl_toolkits) and reinstalling/upgrading with: pip install --upgrade 'matplotlib[mplot3d]'
- Adding this line to /usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py : from matplotlib.cbook import _string_to_bool
Both of these don't work and I am still getting the same error. Any suggestions? Thanks!
self._draw_grid = cbook._string_to_bool(b)
. If it isn't, then you have another version installed. I think it doesnt help too much replacing single lines somewhere in the code, but you rather need to make sure you have the correct version. It shouldn't matter if you use 1.5 or 2.0, but make sure you don't mix them.code line A
and version 1 has acode line B
in it. Now you get an error sayingcode line B
. From that you can deduce that it's not version 2 that is run - independent of what some version command tells you. This could be due to different versions installed and the wrong one being run, or due to an unsuccessful or incomplete update. So I would guess the best way is to set it up froom scratch.