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()