Я использую словарь "my_dictionary", содержащий ключ и список, содержащий два элемента int. Словарь - {key : [men_mean, women_mean]}
. Графы: Значения men_mean и women_mean близки к 2000. Всего ключей 400.
Я получаю следующую ошибку:
Ошибка:
----> 5 ax.annotate('{}',format(height), xy=(rect.get_x() + rect.get_width() / 2, height), xytext=(0,maximum),
textcoords="offset points", ha='center', va='bottom')
TypeError: annotate() got multiple values for argument 'xy'
Код:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
labels, list_item = zip(*sorted(my_dictionary.items())
for key, item in my_dictionary.items():
men_means.append(item[0])
women_means.append(item[1])
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
def autolabel(rects, maximum):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, maximum), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1, max(men_means))
autolabel(rects2, max(women_means))
fig.tight_layout()
plt.show()