1 분 소요

4. 스타일

import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' # 글자 폰트
matplotlib.rcParams['font.size'] = 15 # 글자 크기
matplotlib.rcParams['axes.unicode_minus'] = False # 한글 폰트 사용 시, 마이너스 글자가 깨지는 현상을 해결
x = [1, 2, 3]
y = [2, 4, 8]
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205b132730>]

plt.plot(x, y, linewidth=5) # 선 두께 설정
[<matplotlib.lines.Line2D at 0x2205b232700>]

Marker

plt.plot(x, y, marker='o') # 데이터가 있는 부분 표시
[<matplotlib.lines.Line2D at 0x2205b2a6460>]

plt.plot(x, y, marker='o', linestyle='None') 
[<matplotlib.lines.Line2D at 0x2205b307a60>]

plt.plot(x, y, marker='v', markersize=10) 
[<matplotlib.lines.Line2D at 0x2205b3d3310>]

plt.plot(x, y, marker='X', markersize=10) 
[<matplotlib.lines.Line2D at 0x2205b364d90>]

plt.plot(x, y, marker='X', markersize=10, markeredgecolor='red') 
[<matplotlib.lines.Line2D at 0x2205b4347c0>]

plt.plot(x, y, marker='X', markersize=10, markeredgecolor='red', markerfacecolor='yellow') 
[<matplotlib.lines.Line2D at 0x2205b495cd0>]

line style

plt.plot(x, y, linestyle=':')
[<matplotlib.lines.Line2D at 0x2205b508100>]

plt.plot(x, y, linestyle='--')
[<matplotlib.lines.Line2D at 0x2205b569460>]

plt.plot(x, y, linestyle='-.')
[<matplotlib.lines.Line2D at 0x2205b5c8820>]

Color

plt.plot(x, y, color='aqua')
[<matplotlib.lines.Line2D at 0x2205c669040>]

plt.plot(x, y, color='#ff0000') # RGB 값
[<matplotlib.lines.Line2D at 0x2205c6cb4c0>]

plt.plot(x, y, color='b')
[<matplotlib.lines.Line2D at 0x2205c7ef0d0>]

plt.plot(x, y, color='m')
[<matplotlib.lines.Line2D at 0x2205c851370>]

Format

plt.plot(x, y, 'ro--') # color, marker, linestyle
[<matplotlib.lines.Line2D at 0x2205c8b08b0>]

plt.plot(x, y, 'bv:')
[<matplotlib.lines.Line2D at 0x2205c910c70>]

plt.plot(x, y, 'go') # line style : None
[<matplotlib.lines.Line2D at 0x2205c9e6430>]

Abbreviation

plt.plot(x, y, marker='o', mfc='red', ms=10, mec='blue', ls=':')
[<matplotlib.lines.Line2D at 0x2205ca44910>]

Alpha

plt.plot(x, y, marker='o', mfc='red', ms=10, alpha=0.3) # alpha: 투명도 [0~1]
[<matplotlib.lines.Line2D at 0x2205ce29610>]

Graph size

plt.figure(figsize=(4, 3))
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205cf4d8e0>]

plt.figure(figsize=(2, 4))
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205cfa1f70>]

plt.figure(figsize=(3, 4), dpi=50) # dpi: 해상도 (dots per inch), 확대
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205d0c27c0>]

배경색

plt.figure(facecolor='yellow')
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205d11cf40>]

plt.figure(facecolor='#a1c3ff')
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x2205d18c2b0>]

댓글남기기