使用pyplot极坐标投影保存png时出现numpy错误

时间:2017-02-02 10:04:56

标签: python python-3.x matplotlib

此代码(http://matplotlib.org/examples/pylab_examples/polar_demo.html的简化版):

import matplotlib.pyplot as plt

ax = plt.subplot(111, projection='polar')
plt.savefig("fig.png")

导致以下错误:

Traceback (most recent call last):
  File "so.py", line 4, in <module>
    plt.savefig("fig.png")
  File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 561, in savefig
    return fig.savefig(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1422, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 2220, in print_figure
    **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 505, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 451, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1035, in draw
    func(*args)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1097, in draw
    tick.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 235, in draw
    self.gridline.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 551, in draw
    tpath, affine = transf_path.get_transformed_path_and_affine()
  File "/usr/lib/python3/dist-packages/matplotlib/transforms.py", line 2562, in get_transformed_path_and_affine
    self._revalidate()
  File "/usr/lib/python3/dist-packages/matplotlib/transforms.py", line 2539, in _revalidate
    self._transform.transform_path_non_affine(self._path)
  File "/usr/lib/python3/dist-packages/matplotlib/transforms.py", line 2230, in transform_path_non_affine
    self._a.transform_path(path))
  File "/usr/lib/python3/dist-packages/matplotlib/transforms.py", line 2227, in transform_path_non_affine
    return self._a.transform_path_non_affine(path)
  File "/usr/lib/python3/dist-packages/matplotlib/transforms.py", line 2230, in transform_path_non_affine
    self._a.transform_path(path))
  File "/usr/lib/python3/dist-packages/matplotlib/projections/polar.py", line 72, in transform_path_non_affine
    ipath = path.interpolated(path._interpolation_steps)
  File "/usr/lib/python3/dist-packages/matplotlib/path.py", line 553, in interpolated
    vertices = simple_linear_interpolation(self.vertices, steps)
  File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 1712, in simple_linear_interpolation
    result = np.zeros(new_shape, a.dtype)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

崩溃的原因是使用projection='polar',因为没有这个投影它可以正常工作。

我无法尝试显示结果,因为我正在使用没有X Display的远程网络服务器。 使用:

  • python 3.4.3
  • 14.04.5 LTS
  • matplotib 1.3.1

除了matplotlib版本(1.5.1)之外,完全相同的设置适用于不同的机器。我也可以在python2.7中使用它。

我尝试将matplotlib升级到高于1.3的版本,但无法在apt-get存储库中找到它,sudo pip3 install matplotlib==x.x.x失败,以及从源代码构建。

为什么会崩溃的任何想法?

0 个答案:

没有答案