2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

matplotlibによる3次元プロット

Posted at

#背景
pythonで3次元プロットをする時、座標/関数をどのようなデータでプロットメソッドに渡せばいいか調べるのに時間がかかったため、備忘として残す。

#3次元プロットのコード
関数の定義

def function_2(x):
    return x[0]**2 + x[1]**2

3次元プロット

import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

x0 = np.arange(-3, 3, 0.25)
x1 = np.arange(-3, 3, 0.25)
X, Y = np.meshgrid(x0, x1)
w = np.array([X,Y])
z = function_2(w)

fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("x0")
ax.set_ylabel("x1")
ax.set_zlabel("f(x0, x1)")
ax.plot_wireframe(X, Y, z)
plt.show()

#各配列の中身を理解する(ここが大事)
手書きですがご容赦を。
DSC_0127.JPG

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?