Контрольные пробелы между сгруппированными барами в барплоте - PullRequest
1 голос
/ 19 января 2020

Я хотел бы иметь сгруппированный барплот с matplotlib, и я использую код, полученный из https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/barchart.html. К сожалению, промежутки между решетками слишком малы, а высота фигуры также слишком мала. Я просматривал различные веб-сайты (например, https://python-graph-gallery.com/5-control-width-and-space-in-barplots/), но не смог настроить пространство. Может кто-нибудь помочь?

Вот скриншот моего текущего сюжета:

enter image description here

Вот код Juypter:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np


labels = ['Control \n Method 1', 'Method without\n coordination 1', 'Control \n Method 2', 'Control \n Method 3', 'Control \n Method 4' , 'Control \n Method 5']
ed_means = [20, 34, 30, 35, 27, 3]
srdp_means = [25, 32, 34, 20, 25, 3]

x = np.arange(len(labels))  # the label locations
width = 0.30  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, ed_means, width, label='ED')
rects2 = ax.bar(x + width/2, srdp_means, width, label='SRDP')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Optimality in %')
ax.set_title('Scores by group and gender')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.tick_params(axis='both', which='major', labelsize=12)
ax.legend()



def autolabel(rects):
"""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, 3),  # 3 points vertical offset
                textcoords="offset points",
                ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)

fig.tight_layout()

plt.show()
...