0

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!

5
  • In matplotlib 2.0 the line in axes3d.py should be 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. Commented Mar 7, 2017 at 22:24
  • I tried adding this line to my axes3d.py file and I still get the same error. I did check my version and I have matplotlib 2.0.
    – J. P.
    Commented Mar 7, 2017 at 22:33
  • No, the point is that you do not have matplotlib 2.0, even if some command tells you so. It could also be that you have two different versions and the wrong one is used. Such error are usually solved by making a clean reinstall. Commented Mar 8, 2017 at 7:32
  • I checked what version of matplotlib I had, and its 2.0. I actually only upgraded/reinstalled it last week, so it should be the latest one.
    – J. P.
    Commented Mar 8, 2017 at 19:49
  • I hope you do understand my point. Version 2 has a code line A and version 1 has a code line B in it. Now you get an error saying code 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. Commented Mar 9, 2017 at 7:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.