python - Pyplot投影不承认数据: numpy. float64错误

标签 python python-2.7 numpy matplotlib

我使用的是配备 HighSierra、python 2.7 和 Ipython 5.5.0 的 Mac

在 pyplot 中使用任何类型的投影(例如 aitoff、极坐标、锤子等)时,我无法显示或保存图形,除非它是空的。即使我只尝试添加网格,我也已经遇到了问题(当然,还有数据)。

plt.figure(figsize=(8,4.2))
plt.subplot( projection="aitoff")
plt.title("Aitoff projection")
plt.grid(True)
plt.show()

将返回:

---------------------------------------------------------------------------
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 错误,但没有任何效果。

最佳答案

查看the example从 matplotlib 页面来看,坚持 subplot() 的函数签名似乎是个好主意。

subplot(nrows, ncols, index, **kwargs)
#
subplot(3_digit_number, **kwargs)

这里你可能想要一个子图,因此

plt.subplot(111,projection="aitoff")

关于python - Pyplot投影不承认数据: numpy. float64错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48752191/

相关文章:

python 2.7 isinstance 在动态导入的模块类中失败

python - 合并三个相同形状的 NumPy 数组

python - Pycharm pip install 不能在代理后面工作

python - 将 UNC 存储在 JSON 中并加载到字典中

python - 将占总数百分比的列添加到 Pandas 数据框

Python - Django - cardav - 如何实现服务器

python - 将 .txt 数据加载到 10x256 3d numpy 数组中

python - 如何使用python从mongoDB中的10亿个文档中获取随机单个文档?

Python:与 winsound.Beep 最接近的 Linux 和 OSX 等价物是什么?

python-2.7 - 如何对数据框的行应用操作,但影响可变列?