Я знаю, что это старая нить, но я приземлился здесь несколько раз через Google и думаю, что никакой ответ пока не удовлетворен. Попробуйте использовать одну из следующих функций:
def label_bar(ax, bars, text_format, is_inside=True, **kwargs):
"""
Attach a text label to each bar displaying its y value
"""
max_y_value = max(bar.get_height() for bar in bars)
if is_inside:
distance = max_y_value * 0.05
else:
distance = max_y_value * 0.01
for bar in bars:
text = text_format.format(bar.get_height())
text_x = bar.get_x() + bar.get_width() / 2
if is_inside:
text_y = bar.get_height() - distance
else:
text_y = bar.get_height() + distance
ax.text(text_x, text_y, text, ha='center', va='bottom', **kwargs)
def label_barh(ax, bars, text_format, is_inside=True, **kwargs):
"""
Attach a text label to each horizontal bar displaying its y value
"""
max_y_value = max(bar.get_height() for bar in bars)
if is_inside:
distance = max_y_value * 0.05
else:
distance = max_y_value * 0.01
for bar in bars:
text = text_format.format(bar.get_width())
if is_inside:
text_x = bar.get_width() - distance
else:
text_x = bar.get_width() + distance
text_y = bar.get_y() + bar.get_height() / 2
ax.text(text_x, text_y, text, va='center', **kwargs)
Теперь вы можете использовать их для обычных графиков:
bars = ax.bar(x_pos, values, width=0.5, align="center")
value_format = "{:.1%}" # displaying values as percentage with one fractional digit
label_bar(ax, bars, value_format, is_inside=True, color="white")
или для графиков на горизонтальной панели:
horizontal_bars = ax.barh(y_pos, values, width=0.5, align="center")
value_format = "{:.1%}" # displaying values as percentage with one fractional digit
label_barh(ax, horizontal_bars, value_format, is_inside=False, fontweight="bold")
Если у вас есть проблемы со временем или памятью, смотрели ли вы на потоковый API загрузки обычных файлов?
посмотрите эти настройки, по умолчанию ограничение составляет 8 МБ
upload_max_filesize
post_max_size