반응형
Pyplot으로 모든 서브 플로트 위에 하나의 메인 타이틀을 설정하는 방법은 무엇입니까?
사용하고 pyplot
있습니다. 서브 플로트가 4 개 있습니다. 모든 서브 플롯 위에 하나의 메인 타이틀을 설정하는 방법은 무엇입니까? title()
마지막 서브 플롯 위에 설정합니다.
사용 pyplot.suptitle
또는 Figure.suptitle
:
import matplotlib.pyplot as plt
import numpy as np
fig=plt.figure()
data=np.arange(900).reshape((30,30))
for i in range(1,5):
ax=fig.add_subplot(2,2,i)
ax.imshow(data)
fig.suptitle('Main title') # or plt.suptitle('Main title')
plt.show()
이것을 내 자신의 음모에 적용 할 때 유용한 몇 가지 점이 있습니다.
- 나는
fig.suptitle(title)
오히려 사용의 일관성을 선호plt.suptitle(title)
fig.tight_layout()
제목을 사용할 때는fig.subplots_adjust(top=0.88)
- 글꼴 크기에 대한 아래 답변을 참조하십시오
matplotlib 문서의 서브 플롯 데모 에서 가져온 예제 코드 는 마스터 제목으로 조정됩니다.
import matplotlib.pyplot as plt
import numpy as np
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
fig, axarr = plt.subplots(2, 2)
fig.suptitle("This Main Title is Nicely Formatted", fontsize=16)
axarr[0, 0].plot(x, y)
axarr[0, 0].set_title('Axis [0,0] Subtitle')
axarr[0, 1].scatter(x, y)
axarr[0, 1].set_title('Axis [0,1] Subtitle')
axarr[1, 0].plot(x, y ** 2)
axarr[1, 0].set_title('Axis [1,0] Subtitle')
axarr[1, 1].scatter(x, y ** 2)
axarr[1, 1].set_title('Axis [1,1] Subtitle')
# # Fine-tune figure; hide x ticks for top plots and y ticks for right plots
plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)
# Tight layout often produces nice results
# but requires the title to be spaced accordingly
fig.tight_layout()
fig.subplots_adjust(top=0.88)
plt.show()
하위 그림에도 제목이있는 경우 기본 제목 크기를 조정해야 할 수 있습니다.
plt.suptitle("Main Title", size=16)
반응형
'Programing' 카테고리의 다른 글
NTFS 성능 및 대용량 파일 및 디렉토리 (0) | 2020.05.20 |
---|---|
get_or_create를 사용하는 올바른 방법은 무엇입니까? (0) | 2020.05.20 |
Prim과 반대로 Kruskal을 언제 사용해야합니까? (0) | 2020.05.20 |
.NET String을 변경할 수없는 이유는 무엇입니까? (0) | 2020.05.20 |
플러그인에 대해 npm에서 피어 종속성을 사용하는 이유는 무엇입니까? (0) | 2020.05.20 |