⚙️ Matplotlib
📌 Matplotlib 기초
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure()
axes = fig.add_axes([0.5,0,0.5,0.5])
x = np.linspace(start = 0, stop = 10, num=11)
y = x ** 2
axes.plot(x,y,'r')
axes.set_xlabel("X")
axes.set_ylabel("Y")
axes.set_title("MyGraph")
fig = plt.figure()
axes1 = fig.add_axes([0, 0,1,1])
axes2 = fig.add_axes([0.1, 0.5, 0.4, 0.3])
axes1.plot(x, y, "red")
axes1.set_xlabel("X")
axes1.set_ylabel("Y")
axes1.set_title("MainGraph")
axes2.plot(y,x,"g")
axes2.set_xlabel("YY")
axes2.set_ylabel("newX")
axes2.set_title("InnerGraph")
# 1차원
fig, axes = plt.subplots(nrows=1, ncols=3)
i = 0
for ax in axes:
ax.plot(x, y+(i*10), 'r')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title(f'Sub_{i+1}')
i += 1
# 다차원
fig, axes = plt.subplots(nrows=2, ncols=3)
i=0
for ax1 in axes:
for ax2 in ax1:
ax2.plot(x, y+(i*10), 'r')
ax2.set_xlabel('x')
ax2.set_ylabel('y')
ax2.set_title('title'+str(i))
i = i+1
fig.tight_layout()
📌 Matplotlib 옵션
fig = plt.figure(figsize=(12,6), dpi=100)
outPath = "matOutPic.png"
fig.savefig(outPath)
ax.legend(loc=2)
ax.set_xlabel(r'$\alpha$', fontsize=15)
ax.plot(x, x**2+10, color="#1155dd",label="$y=x^2+10$")
# 선 두께
ax.plot(x, x**2, color="blue", linewidth=0.10)
# 선 모양
ax.plot(x, x**2+15, color="red", lw=3, linestyle='-')
# 점 모양
ax.plot(x, x**2+45, color="green", lw=4, ls='--', marker='o', markersize=6,
markerfacecolor="red", markeredgecolor="yellow",markeredgewidth=3)
# 내부 격자
axes[0].grid(True)
axes[1].grid(color='blue', alpha=0.5, linestyle='dashed', linewidth=2)
# 외부 격자
axes[0].spines['bottom'].set_color('blue')
axes[1].spines['top'].set_color("yellow")
axes[1].spines['top'].set_linewidth(10)
ax2 = ax1.twinx()
ax2.plot()
for label in ax1.get_yticklabels():
label.set_color("blue")