μ λ² λ°μ΄ν° μκ°ν ν¬μ€ν μ μ΄μ΄μ μ¬λ¬ λ°©λ²μ μΆκ°λ‘ λ 곡λΆν΄λ³΄λ €κ³ ν©λλ€!
2022.02.24 - [λ°μ΄ν° λΆμ/Data Visualizaton] - [λ°μ΄ν° μκ°ν] 1. MATPLOTLIB(1)
[λ°μ΄ν° μκ°ν] 1. MATPLOTLIB(1)
Data Visualization λ°μ΄ν° μκ°νκ° νμν μ΄μ 1) μ 보λ₯Ό λ μ½κ² μ λ¬ 2) λ£λ μ¬λμ΄ λ μ½κ² μ΄ν΄ => λΉ λ₯Έ μμ¬κ²°μ μκ°νλ λΉ λ°μ΄ν° μλμ νμμ μ΄λ€! Matplotlib Matplotlib ν¨ν€μ§λ νμ΄μ¬μμ
xod22.tistory.com
μ€μ΅
1. ν¨ν€μ§ μν¬νΈ
# import
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
import sympy
2. μμ νννκΈ°
# x,y λ°μ΄ν° / yμ μ μ
λ ₯
x = np.linspace(0, 50, 500)
y = np.sin(x) * np.exp(-x/10)
# λμ΄λ₯Ό 8, λμ΄λ₯Ό 2λ‘ μ§μ
fig, ax = plt.subplots(figsize=(8, 2))
ax.plot(x, y, lw=2)
# xμΆ, yμΆ labelμ§μ
ax.set_xlabel ("x", labelpad=5, fontsize=12,color="red")
ax.set_ylabel ("f(x)", labelpad=15, fontsize=12, color="green")
# titleμ§μ
ax.set_title("axis labels and title example", fontsize=16, color="blue")
3. μλ‘μ΄ μκ°ν λ°©λ²
~3D Plots~
λ€μκ³Ό κ°μ sinκ·Έλνλ₯Ό μ°¨νΈλ‘ νννκ³ μΆμ λ 3Dνλμ μ¬μ©ν μ μλ€.
from mpl_toolkits import mplot3d
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2+Y**2))
fig = plt.figure()
ax = plt.axes(projection='3d')
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z)
-> plotting ν΄μ€ κ²°κ³Ό!
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 50)
# 50-> κ°κ²©μ μ΄μ΄νκ²ν¨
~TreeMap~
μΈκ΅¬λ°μ΄ν°λ₯Ό κ°μ§κ³ TreeMap μ€μ΅μ μ§νν΄λ³΄κ² μ΅λλ€!
-ν¨ν€μ§ λ€μ΄
pip install plotly
-2002λ κΈ°μ€μ μΈκ΅¬μλͺ μ κΈ°μ€μΌλ‘ μΈκ³ κ°κ΅μ νΈλ¦¬λ§΅μ 그리λ λ¬Έμ
import plotly.express as px
import numpy as np
df = px.data.gapminder().query("year == 2002")
-'continent' : λλ₯ / values='pop' : ν¬κΈ°=μΈκ΅¬(population) / color='lifeExp' : μ=κΈ°λμλͺ
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',color='lifeExp',
color_continuous_scale='RdBu')
fig.show()
'π λ°μ΄ν° λΆμ > 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(1) (0) | 2022.02.24 |