반응형
plot 바깥쪽에 text 쓰기
plt.text(1.03, 0.95, textstr, transform=ax.transAxes, fontsize=14, verticalalignment='top', bbox=props)
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
fig, ax = plt.subplots()
x = 30*np.random.randn(10000)
mu = x.mean()
median = np.median(x)
sigma = x.std()
textstr = '\n'.join((
r'$\mu=%.2f$' % (mu, ),
r'$\mathrm{median}=%.2f$' % (median, ),
r'$\sigma=%.2f$' % (sigma, )))
ax.hist(x, 50)
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
plt.text(1.03, 0.95, textstr, transform=ax.transAxes, fontsize=14, verticalalignment='top', bbox=props)
plt.show()
예제는 upper left 위치
https://matplotlib.org/3.1.0/gallery/recipes/placing_text_boxes.html
반응형
'Python > Matplotlib' 카테고리의 다른 글
[Python] matplotlib - plot 수직선, 수평선 그리기 (0) | 2020.08.25 |
---|---|
[Python] matplotlib - plot 이미지 저장 (0) | 2020.08.25 |
[Python] matplotlib - axvspan, hatch 면적, 패턴 그리기 (0) | 2020.02.26 |
[Python] matplotlib - plot 폰트 크기 변경 (0) | 2019.07.29 |