Data Visualization
λ°μ΄ν° μκ°νκ° νμν μ΄μ
1) μ 보λ₯Ό λ μ½κ² μ λ¬
2) λ£λ μ¬λμ΄ λ μ½κ² μ΄ν΄ => λΉ λ₯Έ μμ¬κ²°μ
μκ°νλ λΉ λ°μ΄ν° μλμ νμμ μ΄λ€!
Matplotlib
Matplotlib ν¨ν€μ§λ νμ΄μ¬μμ λ°μ΄ν° μκ°νλ₯Ό ν λ κ°μ₯ μ λͺ ν λΌμ΄λΈλ¬λ¦¬μ λλ€!
κ°λ¨ν μ€μ΅μ ν΄λ³΄κ² μ΅λλ€.
import matplotlib.pyplot as plt
values=[1,5,7,8,2,0,3,10,4,7]
plt.plot(range(1,11), values)
1. Axis, Ticks and grids
# μ°¨νΈμ νμ λ§λ€μ
ax=plt.axes()
# xμΆμ 0~11 / yμΆμ -1~11
ax.set_xlim([0,11])
ax.set_ylim([-1,11])
# xλκΈ / yλκΈ μ§μ
ax.set_xticks([1,2,3,4,5,6,7,8,9,10])
ax.set_yticks([0,1,2,3,4,5,6,7,8,9,10])
# μ°¨νΈμ μμΉλ₯Ό μ§μ΄λ£μ
plt.plot(range(1,11), values)
#격μ μΆκ°-> λ°μ΄ν° ν¬μΈνΈ νμ
μ μν΄
ax.grid()
2. line styles
plt.plot(range(1,11), values, 'r') #λΉ¨κ°μ
plt.plot(range(1,11), values2,'b') #νλμ
plt.plot(range(1,11), values3,'y') #λ
Έλμ
plt.plot(range(1,11), values4,'g') #μ΄λ‘μ
plt.plot(range(1,11), values, 'c') #νλμ
plt.plot(range(1,11), values2,'m') #보λΌμ
plt.plot(range(1,11), values3,'k') #κ²μμ
+ line λμ μ point(μ )μΌλ‘ νν κ°λ₯!
# μ μΌλ‘ λ³κ²½ κ°λ₯
plt.plot(range(1,11), values, '.') #κ·Έλ₯μ
plt.plot(range(1,11), values2, 's') #Square=>μ μ¬κ°ν
plt.plot(range(1,11), values3, 'o') #μ
plt.plot(range(1,11), values4, 'v') #μμΌκ°ν
plt.plot(range(1,11), values, '*') #*
plt.plot(range(1,11), values2, '+') #+
plt.plot(range(1,11), values3, 'x') #x
plt.plot(range(1,11), values4, 'D') #Diamond=>λ§λ¦λͺ¨
3. text μΆκ°νκΈ°
# xμΆλͺ
, yμΆλͺ
μ§μ
values = [1, 5, 8, 9, 2, 0, 3, 10, 4, 7]
plt.xlabel('Entries')
plt.ylabel('Values')
plt.plot(range(1,11), values)
xμΆλͺ λ° yμΆλͺ μ΄ μ§μ λ κ²μ νμΈν μ μλ€!
+μ μ°μ΄μ§ μμ§λ§ μ£Όμ μΆκ°νλ λ°©λ²
# μνλ μμΉμ text μΆκ°
values = [1, 5, 8, 9, 2, 0, 3, 10, 4, 7]
plt.text(1,1, 'First Entry')
plt.text(5,8,'Off the tangent')
plt.plot(range(1,11), values)
~λ²λ‘ μΆκ°νκΈ°~
values = [1, 5, 8, 9, 2, 0, 3, 10, 4, 7]
values2 = [3, 8, 9, 2, 1, 2, 4, 7, 6, 6]
plt.plot(range(1,11), values, label="first")
plt.plot(range(1,11), values2)
plt.legend(['First', 'Second'], loc=4)
plt.legend()ν¨μλ λ²λ‘λ₯Ό μΆκ°νλ€λ μλ―Έ!
loc=1/2/3/4 μ΅μ μ μ€ μ μλλ°
μ«μ 1,2,3,4λ λ²λ‘μ μμΉλ₯Ό λ§νλ©°, 1 : μ€λ₯Έμͺ½ μλ¨ / 2: μΌμͺ½ μλ¨ / 3 : μΌμͺ½ νλ¨ / 4 : μ€λ₯Έμͺ½ νλ¨
4. PIE CHART
# Pie Chart
values = [5, 8, 9, 10, 4, 7]
# μμ§μ
colors = ['b', 'g', 'r', 'c', 'm', 'y']
# 컬λΌλͺ
labels = ['A', 'B', 'C', 'D', 'E', 'F']
# κ°κ²©μ§μ / Bλ§ νμ΄λμ€κ² 0.2λ‘ κ° μ§μ
explode = (0, 0.2, 0, 0, 0, 0)
# autopct='%1.1f%%' -> μμμ νμ리κΉμ§ %λ‘ νκΈ°νκ² λ€λ μλ―Έ
plt.pie(values, colors=colors, labels=labels,explode=explode, autopct='%1.1f%%')
plt.title('Values')
5. Bar Graph
# Bar graph
values = [5, 8, 9, 10, 4, 7]
# λμ΄ -> Bλ§ κ°μ‘°
widths = [0.7, 0.8, 0.7, 0.7, 0.7, 0.7]
# color -> Bλ§ λΉ¨κ°μ
colors = ['b', 'r', 'b', 'b', 'b', 'b']
plt.bar(range(0, 6), values, width=widths, color=colors, align='center')
6. Histogram
# Histogram
import numpy as np
np.random.seed(0)
x = 20 * np.random.randn(10000)
plt.hist(x, 25, range=(-50, 50), histtype='stepfilled',
align='mid', color='g', label='Test Data')
# λ²λ‘
plt.legend()
# μ λͺ© μ§μ
plt.title('Step Filled Histogram')
'π λ°μ΄ν° λΆμ > 03. Data Visualizaton' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[λ°μ΄ν° μκ°ν] μκ°ν μ€μ΅ - 4 by 4 scatter plot (0) | 2022.03.05 |
---|---|
[λ°μ΄ν° μκ°ν] μκ°ν μ€μ΅ - Scatter plot (0) | 2022.03.02 |
[λ°μ΄ν° μκ°ν] μκ°ν μ€μ΅ - Bar graph (0) | 2022.03.02 |
[λ°μ΄ν° μκ°ν] μκ°ν μ€μ΅ - Pie chart (0) | 2022.03.01 |
[λ°μ΄ν° μκ°ν] 1. MATPLOTLIB(2) (0) | 2022.03.01 |