728x90

그래프를 그리는 라이브러리 MatPlotLib를 소개한다.

MatPlotLib  공식사이트는 아래와 같다.

 

사이트에서 제공하는 예제로 테스트 해보자.

 

https://matplotlib.org/

 

Matplotlib — Visualization with Python

seaborn seaborn is a high level interface for drawing statistical graphics with Matplotlib. It aims to make visualization a central part of exploring and understanding complex datasets. statistical data visualization Cartopy Cartopy is a Python package des

matplotlib.org

 

https://matplotlib.org/stable/gallery/mplot3d/2dcollections3d.html#sphx-glr-gallery-mplot3d-2dcollections3d-py

 

Plot 2D data on 3D plot — Matplotlib 3.8.2 documentation

Plot 2D data on 3D plot Demonstrates using ax.plot's zdir keyword to plot 2D data on selective axes of a 3D plot. import matplotlib.pyplot as plt import numpy as np ax = plt.figure().add_subplot(projection='3d') # Plot a sin curve using the x and y axes. x

matplotlib.org

 

폴더를 만들고 위 사이트에서 만든 폴더에 다운로드해서 저장하고 아래 순서대로 실행한다.

※ 순서

1. python.exe -m pip install --upgrade pip
2. pip install virtualenv

폴더 생성 및 해당폴더로 이동
3. python -m virtualenv venv
4. .\venv\Scripts\activate
5. pip install matplotlib

6. python 2dcollections3d.py

※ 소스

"""
=======================
Plot 2D data on 3D plot
=======================

Demonstrates using ax.plot's *zdir* keyword to plot 2D data on
selective axes of a 3D plot.
"""

import matplotlib.pyplot as plt
import numpy as np

ax = plt.figure().add_subplot(projection='3d')

# Plot a sin curve using the x and y axes.
x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi) / 2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='curve in (x, y)')

# Plot scatterplot data (20 2D points per colour) on the x and z axes.
colors = ('r', 'g', 'b', 'k')

# Fixing random state for reproducibility
np.random.seed(19680801)

x = np.random.sample(20 * len(colors))
y = np.random.sample(20 * len(colors))
c_list = []
for c in colors:
    c_list.extend([c] * 20)
# By using zdir='y', the y value of these points is fixed to the zs value 0
# and the (x, y) points are plotted on the x and z axes.
ax.scatter(x, y, zs=0, zdir='y', c=c_list, label='points in (x, z)')

# Make legend, set axes limits and labels
ax.legend()
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Customize the view angle so it's easier to see that the scatter points lie
# on the plane y=0
ax.view_init(elev=20., azim=-35, roll=0)

plt.show()

※ 화면

 

728x90
반응형

+ Recent posts