반응형
Python 3D 플로팅 연습하기
1) x, y, z 랜덤값 플로팅 (marker='v')
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# Single Points
ax = plt.axes(projection="3d")
x_data = np.random.randint(0, 100, (500,))
y_data = np.random.randint(0, 100, (500,))
z_data = np.random.randint(0, 100, (500,))
ax.scatter(x_data, y_data, z_data, marker="v")
plt.show()
|
cs |
2) x, y, z 랜덤값 플로팅 (marker='v', alpha=0.1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# Single Points
ax = plt.axes(projection="3d")
x_data = np.random.randint(0, 100, (500,))
y_data = np.random.randint(0, 100, (500,))
z_data = np.random.randint(0, 100, (500,))
# ax.scatter(x_data, y_data, z_data, marker="v")
ax.scatter(x_data, y_data, z_data, marker="v", alpha=0.1)
plt.show()
|
cs |
3) x, y, z 지정값 플로팅 (projection="3d")
1
2
3
4
5
6
7
8
|
ax = plt.axes(projection="3d")
x_data = np.arange(0, 50, 0.1)
x_data = np.arange(0, 50, 0.1)
z_data = x_data * y_data
ax.plot(x_data, y_data, z_data)
plt.show()
|
cs |
4) x, y, z 지정값 플로팅 (projection="3d", xlabel, ylabel, zlabel)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
ax = plt.axes(projection="3d")
x_data = np.arange(0, 50, 0.1)
x_data = np.arange(0, 50, 0.1)
z_data = np.sin(x_data) * np.cos(y_data)
ax.plot(x_data, y_data, z_data)
ax.set_title("Funny Function")
ax.set_xlabel("My X Values (cm)")
ax.set_ylabel("My Y Values (V)")
ax.set_zlabel("My Fancy Results (cm*V)")
plt.show()
|
cs |
5) x, y, z 지정값 surface 플로팅 (projection="3d", plot_surface(X, Y, Z))
1
2
3
4
5
6
7
8
9
10
|
ax = plt.axes(projection="3d")
x_data = np.arange(0, 50, 0.1)
y_data = np.arange(0, 50, 0.1)
X, Y = np.meshgrid(x_data, y_data)
Z = X * Y
ax.plot_surface(X, Y, Z)
plt.show()
|
cs |
6) x, y, z 지정값 surface 플로팅 (projection="3d", plot_surface(X, Y, Z))
1
2
3
4
5
6
7
8
9
10
|
ax = plt.axes(projection="3d")
x_data = np.arange(-5, 5, 0.1)
y_data = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(x_data, y_data)
Z = np.sin(X) * np.cos(Y)
ax.plot_surface(X, Y, Z)
plt.show()
|
cs |
6) x, y, z 지정값 surface 플로팅 (projection="3d", plot_surface(X, Y, Z, cmap="plasma"))
1
2
3
4
5
6
7
8
9
10
|
ax = plt.axes(projection="3d")
x_data = np.arange(-5, 5, 0.1)
y_data = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(x_data, y_data)
Z = np.sin(X) * np.cos(Y)
ax.plot_surface(X, Y, Z, cmap="plasma")
plt.show()
|
cs |
7) x, y, z 지정값 surface 플로팅 (projection="3d", plot_surface(X, Y, Z, cmap="plasma")
view_init(azim=0, elev=90) (plot을 바라보는 각도 조절)
1
2
3
4
5
6
7
8
9
10
11
|
ax = plt.axes(projection="3d")
x_data = np.arange(-5, 5, 0.1)
y_data = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(x_data, y_data)
Z = np.sin(X) * np.cos(Y)
ax.plot_surface(X, Y, Z, cmap="plasma")
ax.view_init(azim=0, elev=90)
plt.show()
|
cs |
반응형
'공부 > 파이썬 Python' 카테고리의 다른 글
Pomodoro 뽀모도로 공부 타이머 만들기 (feat. Python, Threading) (0) | 2022.01.23 |
---|---|
파이썬으로 3D 게임 만들기 (feat. Ursina) (0) | 2022.01.23 |
Python에서 나만의 HTTP Server 만들기 (0) | 2022.01.03 |
Matplotlib 애니메이션으로 Linear Regression 표현하기 (0) | 2021.12.26 |
Python으로 캔들스틱 주가 시각화하기 (0) | 2021.12.21 |
댓글