Processor

【Matplotlib】 축 레이블 설정하기

작성자 임베디드코리아 작성일26-04-15 00:01 조회93회 댓글0건
Matplotlib 축 레이블 설정하기
◆ matplotlib.pyplot 모듈의  그래프의 x, y 축에 대한 레이블을 표시할 수 있다.
◆ xlabel(), ylabel() 함수를 사용한다.

---<< 함수 >>-----------------------------------------------------------------------------------
◎ plt.xlabel('X축 이름'),
◎ plt.ylabel('Y축 이름')


---< 예제 : label.py >--------------------------------------------------
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.xlabel('X-Label')
plt.ylabel('Y-Label')
plt.show()
_____________________________________________________________________________

---<예제 : labelpad.py 여백 지정하기 >---------------------------------
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [2, 3, 5, 10])
plt.xlabel('X-Axis', labelpad=15)
plt.ylabel('Y-Axis', labelpad=20)
plt.show()
_______________________________________________________________________________

---< 예제 : Fontdict.01py  폰트 설정하기 >----------------------------------
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [2, 3, 5, 10])
plt.xlabel('X-Axis', labelpad=15, fontdict={'family': 'serif', 'color': 'b', 'weight': 'bold', 'size': 14})
plt.ylabel('Y-Axis', labelpad=20, fontdict={'family': 'fantasy', 'color': 'deeppink', 'weight': 'normal', 'size': 'xx-large'})
plt.show()
_____________________________________________________________________________________


---< 예제 : Fontdict.01py  폰트 설정하기 >----------------------------------
import matplotlib.pyplot as plt

font1 = {'family': 'serif',
        'color': 'b',
        'weight': 'bold',
        'size': 14
        }

font2 = {'family': 'fantasy',
        'color': 'deeppink',
        'weight': 'normal',
        'size': 'xx-large'
        }

plt.plot([1, 2, 3, 4], [2, 3, 5, 10])
plt.xlabel('X-Axis', labelpad=15, fontdict=font1)
plt.ylabel('Y-Axis', labelpad=20, fontdict=font2)
plt.show()
_______________________________________________________________________

---< 예제 : Label_Position.py  레이블 위치 지정하기 >---------------------
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [2, 3, 5, 10])
plt.xlabel('X-Axis', loc='right')
plt.ylabel('Y-Axis', loc='top')
plt.show()
_________________________________________________________________________________
▶ xlabel() 함수의 loc 파라미터는 X축 레이블의 위치를 지정. ({‘left’, ‘center’, ‘right’})
▶ ylabel() 함수의 loc 파라미터는 Y축 레이블의 위치를 지정. ({‘bottom’, ‘center’, ‘top’})