import matplotlib.pyplot as plt # 설치시 pip install matplotlib
[경우1] figure을 1개 + 내부에 axes를 2개 만드는 경우
[경우2] figure을 2개 + 내부에 axes를 1개씩 만드는 경우
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,50)
y1 = np.cos(4*np.pi*x)
y2 = np.cos(4*np.pi*x)*np.exp(-2*x)
plt.plot(x,y1,'r-*',lw=1)
plt.plot(x,y2,'b--',lw=1)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,50)
y1 = np.cos(4*np.pi*x)
y2 = np.cos(4*np.pi*x)*np.exp(-2*x)
# Figure 객체를 생성 후 직접 axes를 생성
fig = plt.figure()
ax = fig.subplots()
ax.plot(x,y1,'r-*',lw=1)
ax.plot(x,y2,'b--',lw=1)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# 사용 데이터 설정
x = np.linspace(0, 10, 100)
y = 4 + 2 * np.sin(2 * x)
# 방법1
plt.plot(x, y)
# 방법2
fig, ax = plt.subplots()
ax.plot(x, y, linewidth=2.0)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# 사용 데이터 설정
x = 4 + np.random.normal(0, 2, 24)
y = 4 + np.random.normal(0, 2, len(x))
# size and color:
sizes = np.random.uniform(15, 80, len(x))
colors = np.random.uniform(15, 80, len(x))
# 방법1
plt.scatter(x, y, s=sizes, c=colors, vmin=0, vmax=100)
# 방법2
fig, ax = plt.subplots()
ax.scatter(x, y, s=sizes, c=colors, vmin=0, vmax=100)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# 사용 데이터 설정
x = 0.5 + np.arange(8)
y = np.random.uniform(2, 7, len(x))
# 방법1
plt.bar(x, y, width=1, edgecolor="white", linewidth=0.7)
# 방법2
fig, ax = plt.subplots()
ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# 사용 데이터 설정
x = 4 + np.random.normal(0, 1.5, 200)
# 방법1
plt.hist(x, bins=8, linewidth=0.5, edgecolor="white")
# 방법2
fig, ax = plt.subplots()
ax.hist(x, bins=8, linewidth=0.5, edgecolor="white")
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# 사용 데이터 설정
D = np.random.normal((3, 5, 4), (1.25, 1.00, 1.25), (100, 3))
# 방법1
plt.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,
showmeans=False, showfliers=False,
medianprops={"color": "white", "linewidth": 0.5},
boxprops={"facecolor": "C0", "edgecolor": "white",
"linewidth": 0.5},
whiskerprops={"color": "C0", "linewidth": 1.5},
capprops={"color": "C0", "linewidth": 1.5})
# 방법2
fig, ax = plt.subplots()
VP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,
showmeans=False, showfliers=False,
medianprops={"color": "white", "linewidth": 0.5},
boxprops={"facecolor": "C0", "edgecolor": "white",
"linewidth": 0.5},
whiskerprops={"color": "C0", "linewidth": 1.5},
capprops={"color": "C0", "linewidth": 1.5})
plt.show()