Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

시각화

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

1기본 그래프

import matplotlib.pyplot as plt

x = np.arange(10)
plt.plot(x, x ** 2)
plt.show()
시작, 끝, 개수 = 0, 10, 100
x = np.linspace(시작, 끝, 개수)
print(x[:5].round(2), '...', x[-5:].round(2))
plt.plot(x, np.sin(x), label='sine')
plt.plot(x, np.cos(x), label='cosine')
plt.legend() # 범례 표시
plt.show()
xs = np.array([3.0, 4.0])
ys = np.array([4.0, 3.0])
plt.scatter(x=xs, y=ys)
plt.quiver([0, 0], [0, 0], xs, ys,
           angles='xy', scale_units='xy', scale=1, color='r')
plt.xlim(0, 6); plt.ylim(0, 6)
plt.grid()
plt.show()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

Xs = np.array([(0, 0), (0, 1), (1, 0), (1, 1)])
y = {}
y['AND'] = np.array([0, 0, 0, 1])
y['NAND'] = np.where(y['AND'] == 0, 1, 0)
y['OR'] = np.array([0, 1, 1, 1])
display(pd.DataFrame(Xs, columns=['x1', 'x2'])
        # .assign(AND=y['AND'], NAND=y['NAND'], OR=y['OR'])
        .assign(**y)) # 딕셔너리 언패킹 (unpacking)

plt.figure(figsize=(9, 3))
for i, label in enumerate(y.keys() , start=1):
    plt.subplot(1, len(y), i)
    plt.scatter(Xs[:, 0], Xs[:, 1], c=y[label], cmap='bwr')
    plt.grid()
    plt.title(label)
    
plt.tight_layout()
plt.show()