我正在使用带有HighSierra,python 2.7和Ipython 5.5.0的Mac
在pyplot中使用任何类型的投影(例如aitoff,polar,hammer等)时,我无法显示或保存图形,除非它是空的。即使我只尝试添加网格,我已经有问题(当然,也有数据)。
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错误,没有任何效果。
答案 0 :(得分:2)
从matplotlib页面看the example,坚持使用subplot()
subplot(nrows, ncols, index, **kwargs)
#
subplot(3_digit_number, **kwargs)
在这里你可能想要一个子图,因此
plt.subplot(111,projection="aitoff")
答案 1 :(得分:0)
我想出了这个:解决方案是安装numpy 1.11.0,但由于我的计算机中安装了多个,因此无法正常工作。我不得不删除其他版本(如果通过pip安装,这可以手动完成,只需删除文件),或者更改环境以便使用我想要的numpy版本。