2016-12-14 2 views
0

가로 막대 그래프를 만들었으니 이제 막대에 마커를 추가해야합니다. 그렇게하려면 어떻게해야합니까?어떻게 막대 그래프에 파이썬으로 마커를 추가 할 수 있습니까?

코드 지금까지 다음과 같습니다있다 :

enter image description here

def plot_comparison(): 
lengths = [11380, 44547, 166616, 184373, 193068, 258004, 369582, 462795, 503099, 581158, 660724, 671812, 918449] 

y_pos = np.arange(len(length)) 
error = np.random.rand(len(length)) 

plt.barh(y_pos, length, xerr=error, align='center', alpha=0.4) 
plt.yticks(y_pos, length) 
plt.xlabel('Lengths') 
plt.title('Comparison of different cuts') 
plt.show() 
+0

의 사용 가능한 복제 [하기 matplotlib : 라인의 개별 포인트 설정 마커 (http://stackoverflow.com/questions/8409095/matplotlib-set-markers-for-individual-points -on-a-line) –

+0

이 경우 막대 그래프에 표식을 배치해야합니다. – Sanchit795

+0

마커는 줄이 그어진 그래프에만 사용할 수 있습니다. –

답변

1

plot 명령을 추가하여 lengths에 대한 y_pos을 플로팅 할 수 있습니다. 메이커를 지정하고 linestyle을 "" (또는 "none")으로 설정해야합니다. 그렇지 않으면 마커가 직선으로 연결됩니다.
다음 코드는 향후있을 수 있습니다.

import matplotlib.pyplot as plt 
import numpy as np 

lengths = [11380, 44547, 166616, 184373, 193068, 258004, 369582, 462795, 503099, 581158, 660724, 671812, 918449] 

y_pos = np.arange(len(lengths)) 
error = np.array(lengths)*0.08 

plt.barh(y_pos, lengths, xerr=error, align='center', alpha=0.4) 
plt.plot(lengths, y_pos, marker="D", linestyle="", alpha=0.8, color="r") 
plt.yticks(y_pos, lengths) 
plt.xlabel('Lengths') 
plt.title('Comparison of different cuts') 
plt.show() 

enter image description here

관련 문제