matplotlib에 굵은 주석 텍스트를 추가하려면 레이블에 LaTeX 표현을 사용할 수 있습니다.
단계
-
Figure 크기를 설정하고 서브플롯 사이와 주변의 패딩을 조정합니다.
-
x 만들기 및 y numpy를 사용하는 데이터 포인트.
-
각 산점에 대한 레이블을 설정하려면 레이블 목록을 만드십시오.
-
플롯 xpoints, ypoints scatter() 사용 방법. 색상은 xpoint를 사용하세요.
-
압축된 레이블 반복 x포인트 및 ypoints .
-
주석() 사용 for 루프 내부에 굵은 LaTeX 표현이 있는 메소드
-
그림을 표시하려면 show()를 사용하세요. 방법.
예
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
xpoints = np.linspace(1, 10, 10)
ypoints = np.random.rand(10)
labels = ["%.2f" % i for i in xpoints]
plt.scatter(xpoints, ypoints, c=xpoints)
for label, x, y in zip(labels, xpoints, ypoints):
plt.annotate(
f"$\\bf{label}$",
xy=(x, y), xytext=(-20, 20),
textcoords='offset points', ha='center', va='bottom',
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))
plt.show() 출력
