모과 can do

Python matplotlib 그림 x축 글자 겹침 해결 본문

Python 오류 해결

Python matplotlib 그림 x축 글자 겹침 해결

노란 모과 2023. 3. 3. 17:21

한정된 사이즈에 x축에 들어갈 글자들이 너무 많게 되면 다음과 같이 겹쳐서 출력된다. 

해결방법 1 . x축 글자를 45도 회전시키기!
x= sorted_brandnames
y = sorted_brandcount
# 전체 Barplot
plt.figure(figsize=(10, 5))
plt.bar(x=x, height=y) 
plt.title("ALL Brands Frequency BarPlot")
# x축 글자들 회전시키기!
plt.xticks( rotation=45)
plt.xticks()
plt.show()

처음보다는 나아졌지만 아직도 보기 불편하다... 
해결방법 2 . x축 글자를 45도 회전시키기!
plt.xticks( rotation=90)
해결방법 3.  글자사이즈 줄이기
 
 # 글자크기는 8로, 회전은 90도
 plt.xticks(fontsize =8, rotation=90)

해결 완료 :)