gpt4 book ai didi

numpy - mplot3d 教程示例未正常运行

转载 作者:行者123 更新时间:2023-12-04 00:00:26 29 4
gpt4 key购买 nike

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

  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.

我正在使用 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

最佳答案

matplotlib 版本 2.2.2 python 版本 3pyqt 5.9.2

代替

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

尝试

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

两者都适用于我在 Jupyter notebook 上的工作。我怀疑你搞砸了 pyqt

enter image description here

关于numpy - mplot3d 教程示例未正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38640558/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com