-
3차원 그래프 그리기1PYTHON/실습 2020. 12. 11. 16:073차원 그래프를 그리기 위한 라이브러리 임포트-> Axes3D 라는 모듈을 임포트해 3차원 그래프를 그린다import matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dimport numpy as np좌표 생성-> np.meshgird 라는 함수를 통해 좌표로 쓸 2차원 배열을 만든다.x = np.arange(10)y = np.arange(10)x, y = np.meshgrid(x, y)z = 20-x-y
▼▼▼▼
그래프 그리기-> plot_wireframe 이라는 함수를 통해 그물망 모양의 함수를 그린다.# figure 생성fig = plt.figure(figsize=(8,8)) # figsize : 그래프 사이즈# 그래프ax = fig.add_subplot(111, projection='3d') # 111: 1행1열의 첫번째에 생성ax.plot_wireframe(x, y, z)# 타이틀plt.title('TEST')# 축라벨이름ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')plt.show()-> 기울어진 평면이 조금 엉성해서 그래프 스타일을 plot_wireframe 이 아닌 plot_surface를 써봤지만, 영 나이지지 않았다.fig = plt.figure(figsize=(8,8))ax = fig.add_subplot(111, projection='3d')ax.plot_surface(x, y, z)plt.title('TEST')ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')plt.show()'PYTHON > 실습' 카테고리의 다른 글
python - heapq 사용법 (0) 2022.09.28 3차원 그래프 그리기2 (0) 2020.12.11 웹크롤링_중앙일보 (0) 2020.05.28