사용 annotate
.
사실 난 거의 text
을 사용하지 않습니다. 데이터 좌표에 물건을 배치하고 싶을 때도 일반적으로 포인트를 고정 된 거리만큼 오프셋하고 싶습니다. annotate
을 사용하면 훨씬 쉽습니다. 당신이 약간 코너에서 오프셋하고 싶은 경우
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, subplot_kw=dict(aspect=1))
axes[0].plot(range(1, 4))
axes[1].plot(range(10, 40, 10), range(1, 4))
for ax in axes:
ax.annotate('Test', xy=(1, 0), xycoords='axes fraction', fontsize=16,
horizontalalignment='right', verticalalignment='bottom')
plt.show()
, 당신이 어떻게 값을 제어 할 수 textcoords
을 xytext
kwarg을 통해 오프셋 (그리고 지정할 수 있습니다 빠른 예를 들어
이 해석됩니다. 오프셋이 축 아래에 배치하려는 경우
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, subplot_kw=dict(aspect=1))
axes[0].plot(range(1, 4))
axes[1].plot(range(10, 40, 10), range(1, 4))
for ax in axes:
ax.annotate('Test', xy=(1, 0), xycoords='axes fraction', fontsize=16,
xytext=(-5, 5), textcoords='offset points',
ha='right', va='bottom')
plt.show()
, 당신이 사용할 수있는 그것을 세트를 배치 할 : 나는 여기 horizontalalignment
및 verticalalignment
의 ha
및 va
약어를 사용하고 있습니다 포인트 아래 거리 :
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, subplot_kw=dict(aspect=1))
axes[0].plot(range(1, 4))
axes[1].plot(range(10, 40, 10), range(1, 4))
for ax in axes:
ax.annotate('Test', xy=(1, 0), xycoords='axes fraction', fontsize=16,
xytext=(0, -15), textcoords='offset points',
ha='right', va='top')
plt.show()
또한 자세한 내용은 Matplotlib annotation guide을 참조하십시오.
좋은 답변과 예입니다. 텍스트 대신 주석을 사용하려고합니다. 고맙습니다. – Tetsuro
좋은 답변입니다! 고마워! – HyperCube