mathplotlib를
SO : How to plot multiple horizontal bars in one chart with matplotlib에서 사용하여 가로 막대 그래프를 생성 중입니다. 문제는 2 개 이상의 가로 막대가 있고 막대가 겹쳐져있는 경우입니다. 확실하지, 내가 뭘 잘못하고있어. 여기가로 막대 그래프 막대 그래프
import pandas
import matplotlib.pyplot as plt
import numpy as np
df = pandas.DataFrame(dict(graph=['q1','q2','q3' , 'q4','q5',' q6'],
n=[3, 5, 2,3 ,5 , 2], m=[6, 1, 3, 6 , 1 , 3]))
ind = np.arange(len(df))
width = 0.4
opacity = 0.4
fig, ax = plt.subplots()
ax.barh(ind, df.n, width, alpha=opacity, color='r', label='Existing')
ax.barh(ind + width, df.m, width, alpha=opacity,color='b', label='Community')
ax.barh(ind + 2* width, df.m, width, alpha=opacity,color='g', label='Robust')
ax.set(yticks=ind + width , yticklabels=df.graph, ylim=[2*width - 1, len(df)])
ax.legend()
#plt.xlabel('Queries')
plt.xlabel('Precesion')
plt.title('Precesion for these queries')
plt.show()
는 현재 그래프 당신은 0.4 바의 폭을 설정이
유일한 문제는 내가 아닙니다. yaxis 측면에서 요소의 이름을 지정할 수 있습니다. 그것의 열거. yaxis의 0,1,2 대신 http://imgur.com/myoXtQv 사용자 정의 이름을 추가해야합니다. 문서에서 그 작업을 수행하는 방법을 찾을 수 없습니다. 어떤 아이디어? – Rahul
@Rahul : 색인을 설정하면 레이블에 자동으로 사용됩니다. 'df.set_index ('그래프'). plot (kind = 'barh')'. – BrenBarn
아니, 정확히 나를 위해 일하지 않습니다. 레이블을 y 축에 대해 q1, q2 및 q3으로 지정하면됩니다. 그렇다면 판다는 q1의 가치를 기대하고 있습니다. 그렇지 않습니다. 내가 원하는 것은 그것들을 분류하고 그것을 열거하지 않는 것입니다. – Rahul