[Visualization] x 축에 있는 margin 제거하기 (2/2)

2020. 11. 19. 23:59분석 Python/Visualization

728x90

2020/11/19 - [분석 Python/Visualization] - [Visualization] x 축에 중복된 이름 잘 시각화하기 (xticks) (1/2)

2020/11/19 - [분류 전체보기] - [Visualization] x 축에 있는 margin 제거하기 (2/2)

 

지난번 그림이다.

이 그림에서 그림을 예쁘게 처리하기 위해서는 저 마진을 없애면 좋을 것이다.

 

실제로 저것과 관련된 것을 찾아보니 결국 x 축의 limit를 줄이는 방향이면 가능하다.

 

그러면 어떤 것을 얼마나 줄여야 하는 걸까?

바로 xticks 에서 나오는 ticks 의 최소 최대를 건드려주면 되는 것 같다. 

 

## 이전 코드 참고!
plt.figure(figsize=(17,17))
plt.subplots_adjust(left=0.2, bottom=0.5, right=0.99, 
                    top=0.97, wspace=0.05, hspace=0.1)
plt.plot(np.arange(len(result)), result["target"], label ="true")
plt.xticks(ticks = ticks, labels=labels,rotation=0,size=12, va='top', ha='right')
plt.legend()
plt.gca().margins(x=0.1)
plt.gcf().canvas.draw()
tl = plt.gca().get_xticklabels()
maxsize = max([t.get_window_extent().width for t in tl])
m = 0.05 # inch margin
s = maxsize/plt.gcf().dpi*len(exp_result)+2*m
margin = m/plt.gcf().get_size_inches()[0]
plt.xlim(0, len(result)-1) ######## 핵심
plt.gcf().subplots_adjust(left=margin, right=1.-margin)
plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1])
plt.show()

 

굳 !! 

 

728x90