파이플롯으로 간단한 그래프 그리기 :: Python 빅데이터 처리와 시각화 - mindscale
Skip to content

파이플롯으로 간단한 그래프 그리기

pyplot

from matplotlib import pyplot as plt
x = np.linspace(-3, 3, 31)  # -3부터 3까지 31개의 숫자
x
array([-3. , -2.8, -2.6, -2.4, -2.2, -2. , -1.8, -1.6, -1.4, -1.2, -1. ,
       -0.8, -0.6, -0.4, -0.2,  0. ,  0.2,  0.4,  0.6,  0.8,  1. ,  1.2,
        1.4,  1.6,  1.8,  2. ,  2.2,  2.4,  2.6,  2.8,  3. ])
y = x ** 2
y
array([9.  , 7.84, 6.76, 5.76, 4.84, 4.  , 3.24, 2.56, 1.96, 1.44, 1.  ,
       0.64, 0.36, 0.16, 0.04, 0.  , 0.04, 0.16, 0.36, 0.64, 1.  , 1.44,
       1.96, 2.56, 3.24, 4.  , 4.84, 5.76, 6.76, 7.84, 9.  ])
plt.plot(x, y)
[<matplotlib.lines.Line2D at 0x16dcc31cf28>]
plt.plot(x, y, 'o')
[<matplotlib.lines.Line2D at 0x16dcc4d2908>]
plt.plot(x, y, 'o', color='green')
[<matplotlib.lines.Line2D at 0x1b139281c88>]