2016-10-11 4 views
2

간단한 선으로 구성된 플롯이 있습니다. 잠시 동안 으로 보이지 않게 설정했습니다.플롯/그래프에 yticks를 표시하는 방법 (y 축이 아님). 포인트 근처에 시선을 표시하십시오.

import matplotlib.pyplot as plt 
x = [1, 2, 3, 4, 5] 
y = [1, 1.5, 2, 2.5, 3] 

fig, ax = plt.subplots(figsize=(15,10)) 
plt.plot(x, y, 'ko-') 

plt.xlabel('X', fontsize=15) 
plt.ylabel('Y', fontsize=15) 
plt.xticks(x, fontsize=13) 
plt.yticks(y, visible=False) 

plt.margins(0.1, 0.1) 
plt.title('Graph', color='black', fontsize=17) 
ax.axis('scaled') 
ax.grid() 
plt.show() 

I 인쇄에게/yticks 오른쪽 (안 왼쪽) 그래프 자체 표시해야 여기 enter image description here

그래프에 대한 코드이다. 따라서 이고 데이터 포인트가 있습니다.

원하는 출력 : enter image description here


어떻게 하기 matplotlib와 함께 할 방법?

답변

2

축에 텍스트에 주석을 붙이려면 plt.text()을 사용할 수 있습니다. x, y 포인트를 반복함으로써 각 마커에 레이블을 배치 할 수 있습니다. 예를 들어 :

enter image description here

:

import matplotlib.pyplot as plt 
x = [1, 2, 3, 4, 5] 
y = [1, 1.5, 2, 2.5, 3] 

fig, ax = plt.subplots(figsize=(15,10)) 
plt.plot(x, y, 'ko-') 

plt.xlabel('X', fontsize=15) 
plt.ylabel('Y', fontsize=15) 
plt.xticks(x, fontsize=13) 
plt.yticks(y, visible=False) 

offset = 0.05 
for xp, yp in zip(x,y): 
    label = "%s" % yp 
    plt.text(xp-offset, yp+offset, label, fontsize=12, horizontalalignment='right') 

plt.margins(0.1, 0.1) 
plt.title('Graph', color='black', fontsize=17) 
ax.axis('scaled') 
ax.grid() 
plt.show() 

는 다음 그림을 제공합니다