본문 바로가기

언어 꿀Tip/Python 꿀tip!

07_01_46. 2x2 형태로 여러 line 중첩해서 그래프 그리기

  • 2x2 형태 그래프 및 각 그래프에 여러 line 중첩해서 그리기
  • 각 그래프 내에 범례 제거
  • 각 그래프의 축 이름 (label) 제거
from matplotlib import pyplot as plt
import matplotlib.pylab as plt2
import seaborn as sns

# plot 크기 조정
plt2.rcParams["figure.figsize"] = (15,10)
# 2x2 형태 생성
fig, axs = plt.subplots(2,2)

# cd list에 속한 element에 따라 2x2 형태로 plot 그리기
l_cd = ['1','2','3','4']
# Flatten
axx = axs.ravel()
for i, v_cd in enumerate(l_cd):  
    sns.lineplot(x="date", y="amt", hue="cd", data=df_all[df_all['cd']==v_cd], ax=axx[i])
    axx[i].set(ylabel=None)  #y축 label(이름) 제거
#     plt.legend(loc='upper right')  # 범례 위치 조정
    axx[i].legend().remove()  # 범례 제거