Python Pyplot投影不';t允许数据:numpy.float64错误
我使用的是Mac和HighSierra、python 2.7和Ipython 5.5.0 在pyplot中使用任何类型的投影(如aitoff、polar、hammer等)时,除非图形为空,否则无法显示或保存该图形。即使我只是尝试添加网格,我已经有问题了(当然,数据也有问题) 将返回:Python Pyplot投影不';t允许数据:numpy.float64错误,python,python-2.7,numpy,matplotlib,Python,Python 2.7,Numpy,Matplotlib,我使用的是Mac和HighSierra、python 2.7和Ipython 5.5.0 在pyplot中使用任何类型的投影(如aitoff、polar、hammer等)时,除非图形为空,否则无法显示或保存该图形。即使我只是尝试添加网格,我已经有问题了(当然,数据也有问题) 将返回: --------------------------------------------------------------------------- TypeError
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.pyc in draw(self, renderer)
1032 dsu.sort(key=itemgetter(0))
1033 for zorder, a, func, args in dsu:
-> 1034 func(*args)
1035
1036 renderer.close_group('figure')
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.pyc in draw(self, renderer, inframe)
2084
2085 for zorder, a in dsu:
-> 2086 a.draw(renderer)
2087
2088 renderer.close_group('axes')
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1094
1095 for tick in ticks_to_draw:
-> 1096 tick.draw(renderer)
1097
1098 # scale up the axis label box to also find the neighbors, not
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.pyc in draw(self, renderer)
232 if midPoint:
233 if self.gridOn:
--> 234 self.gridline.draw(renderer)
235 if self.tick1On:
236 self.tick1line.draw(renderer)
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/lines.pyc in draw(self, renderer)
548 funcname = self._lineStyles.get(self._linestyle, '_draw_nothing')
549 if funcname != '_draw_nothing':
--> 550 tpath, affine = transf_path.get_transformed_path_and_affine()
551 if len(tpath.vertices):
552 self._lineFunc = getattr(self, funcname)
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.pyc in get_transformed_path_and_affine(self)
2560 the path necessary to complete the transformation.
2561 """
-> 2562 self._revalidate()
2563 return self._transformed_path, self.get_affine()
2564
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.pyc in _revalidate(self)
2537 or self._transformed_path is None):
2538 self._transformed_path = \
-> 2539 self._transform.transform_path_non_affine(self._path)
2540 self._transformed_points = \
2541 Path(self._transform.transform_non_affine(self._path.vertices),
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.pyc in transform_path_non_affine(self, path)
2228 else:
2229 return self._b.transform_path_non_affine(
-> 2230 self._a.transform_path(path))
2231 transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__
2232
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.pyc in transform_path_non_affine(self, path)
2225 return path
2226 elif not self._a.is_affine and self._b.is_affine:
-> 2227 return self._a.transform_path_non_affine(path)
2228 else:
2229 return self._b.transform_path_non_affine(
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.pyc in transform_path_non_affine(self, path)
2225 return path
2226 elif not self._a.is_affine and self._b.is_affine:
-> 2227 return self._a.transform_path_non_affine(path)
2228 else:
2229 return self._b.transform_path_non_affine(
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/projections/geo.pyc in transform_path_non_affine(self, path)
288 def transform_path_non_affine(self, path):
289 vertices = path.vertices
--> 290 ipath = path.interpolated(self._resolution)
291 return Path(self.transform(ipath.vertices), ipath.codes)
292 transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/path.pyc in interpolated(self, steps)
551 return self
552
--> 553 vertices = simple_linear_interpolation(self.vertices, steps)
554 codes = self.codes
555 if codes is not None:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/cbook.pyc in simple_linear_interpolation(a, steps)
1709 new_shape = list(a.shape)
1710 new_shape[0] = new_length
-> 1711 result = np.zeros(new_shape, a.dtype)
1712
1713 result[0] = a[0]
TypeError: 'numpy.float64' object cannot be interpreted as an index
最后,我尝试了更新所有内容,并按照其他一些帖子中的建议对这个numpy错误进行了降级,但没有任何效果。从matplotlib页面上看,坚持函数签名似乎是个好主意
在这里,您可能需要一个子地块,因此
plt.subplot(111,projection="aitoff")
我明白了:解决方案是安装numpy 1.11.0,但由于我的计算机中安装了几次,所以它无法工作。我不得不删除其他版本(如果通过pip安装,这可以手动完成,只需删除文件),或者更改环境以使用我想要的numpy版本。您使用的是哪个版本的matplotlib?我使用的是matplotlib 2.1.2,我对此表示怀疑。在matplotlib 2.1.2中,引起错误的函数位于代码中第1500行附近,而您在第1700行附近显示它。这是我键入help(matplotlib)时得到的结果。无论如何,我发现了,我安装了2台numpy,它在电脑的其他地方使用了1.14。现在我将环境更改为使用numpy 1.11.0(也许matplotlib就是这样的)。谢谢你的帮助!
subplot(nrows, ncols, index, **kwargs)
#
subplot(3_digit_number, **kwargs)
plt.subplot(111,projection="aitoff")