Использование гистограмм в python - PullRequest
0 голосов
/ 26 марта 2020

Я пытаюсь сравнить 10 наборов данных в гистограмме, и я хотел бы, чтобы они были рядом друг с другом. Я получу sh, чтобы получить более широкую диаграмму, чтобы я мог увеличить ширину, потому что когда я увеличиваю ширину полос, полосы пересекаются друг с другом, как показано на рисунке 2. Спасибо.

menMeans = (20, 35, 30, 35, 27)

ind = np.arange(N)  # the x locations for the groups
width = 0.35/5    # the width of the bars

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, f_current_ratio, width, color='lightblue')
rects2 = ax.bar(ind+width, vowg_current_ratio, width, color='green')
rects3 = ax.bar(ind+2*width, toyota_current_ratio, width, color='orange')
rects4 = ax.bar(ind+3*width, daign_current_ratio, width, color='royalblue')
rects5 = ax.bar(ind+4*width, gm_current_ratio, width, color='gold')
rects6 = ax.bar(ind+5*width, honda_current_ratio, width, color='grey')
rects7 = ax.bar(ind+6*width, saic_current_ratio, width, color='purple')
rects8 = ax.bar(ind+7*width, fcha_current_ratio, width, color='indigo')
rects9 = ax.bar(ind+8*width, bmwg_current_ratio, width, color='black')

# add some
ax.set_ylabel('Current Ratio')
ax.set_title('Current Ratio By Year and Company')
ax.set_xticks(ind + width*5)
ax.set_xticklabels( ('2019', '2018', '2017', '2016') )

ax.legend( (rects1[0], rects2[0]), ('f', 'vowg') )

#labelling
def autolabel(rects):
    """
    Attach a text label above each bar displaying its height
    """
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
                '%.2f' %(height),
                ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
fig.tight_layout()
plt.show()

Изображение 1: https://prnt.sc/rn6h9i Изображение 2: https://prnt.sc/rn6hj9

...