mplot3d教程示例未按预期运行

时间:2016-07-28 15:22:04

标签: numpy matplotlib

我在尝试运行standard matplotlib examples from the documentation时遇到了问题。对于pringle示例使用plot_trisurf绘制三维曲面,会出现两个错误:

  1. 一个错误:

    /Library/Python/2.7/site-packages/matplotlib-override/matplotlib/collections.py:764: RuntimeWarning: invalid value encountered in sqrt   scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor
    
    1. 每个点都有错误:

      Jul 28 11:12:13  python[77168] <Error>: void CGPathCloseSubpath(CGMutablePathRef _Nullable): no current point.
      
    2. 我使用matplotlib 1.5.1 这是我使用的源/示例代码:

      from mpl_toolkits.mplot3d import Axes3D
      from matplotlib import cm
      import matplotlib.pyplot as plt
      import numpy as np
      
      n_angles = 36
      n_radii = 8
      
      # An array of radii
      # Does not include radius r=0, this is to eliminate duplicate points
      radii = np.linspace(0.125, 1.0, n_radii)
      
      # An array of angles
      angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
      
      # Repeat all angles for each radius
      angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
      
      # Convert polar (radii, angles) coords to cartesian (x, y) coords
      # (0, 0) is added here. There are no duplicate points in the (x, y) plane
      x = np.append(0, (radii*np.cos(angles)).flatten())
      y = np.append(0, (radii*np.sin(angles)).flatten())
      
      # Pringle surface
      z = np.sin(-x*y)
      
      fig = plt.figure()
      ax = fig.gca(projection='3d')
      
      ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
      
      plt.show()
      

      这是情节:

      enter image description here

1 个答案:

答案 0 :(得分:0)

matplotlib版本2.2.2 python版本3 pyqt 5.9.2

代替

ax = fig.gca(projection='3d')

尝试

ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=45, azim=134)

两者在Jupyter笔记本上都对我有用。 我怀疑您搞砸了pyqt

enter image description here