LoginSignup
0
0

More than 1 year has passed since last update.

3D scatterのRuntimeWarningエラー

Last updated at Posted at 2021-07-31

RuntimeWarning: invalid value encountered in sqrt

問題コード
plt.subplot(111, projection='3d')
plt.scatter(X, Y, Z)
出力
RuntimeWarning: invalid value encountered in sqrt
  scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor

解決策

解決コード
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z)

全体コード
import matplotlib.pyplot as plt
from sklearn.datasets import make_swiss_roll
X, t = make_swiss_roll(n_samples=1000)

# RuntimeWarningエラー
plt.subplot(111, projection='3d')
plt.scatter(X[:,0], X[:,1], X[:,2], c=t)
plt.show()

# 成功
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:,0], X[:,1], X[:,2], c=t)
plt.show()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0