Python 条形图中分组条形图之间的控制空间

Python 条形图中分组条形图之间的控制空间,python,matplotlib,bar-chart,Python,Matplotlib,Bar Chart,我希望有一个带有matplotlib的分组条形图,并使用从中获取的代码。 不幸的是,酒吧之间的空间太小,人物的高度也太小。我看了不同的网站(像这样),但无法调整空间。有人能帮忙吗 以下是我当前情节的屏幕截图: 以下是Juypter代码: import matplotlib import matplotlib.pyplot as plt import numpy as np labels = ['Control \n Method 1', 'Method without\n coordina

我希望有一个带有matplotlib的分组条形图,并使用从中获取的代码。 不幸的是,酒吧之间的空间太小,人物的高度也太小。我看了不同的网站(像这样),但无法调整空间。有人能帮忙吗

以下是我当前情节的屏幕截图:

以下是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()

酒吧位置之间的空间庄严地由可用的总空间除以酒吧数量决定。您可以使用更大的数字,也可以缩小标签。@PeterBe要缩小标签,旋转标签可以是一个选项。对于您的答案,请选择“重要的答案”(Beingernest和JohanC)。我尝试使用“plt.figure(figsize=(70,70),dpi=400)”将图片放大,但没有成功。如前所述,您需要确保图片适合您的屏幕。例如,
plt.subplot(figsize=(13,8),dpi=100)
应该可以工作。在这种情况下,您运行的代码与问题中所示的代码不完全相同-建议修改为添加
figsize=(13,8),dpi=100
作为
plt.subplot()的参数
。杆位之间的间距庄严地由可用总空间除以杆数决定。您可以使用更大的数字,也可以缩小标签。@PeterBe要缩小标签,旋转标签可以是一个选项。对于您的答案,请选择“重要的答案”(Beingernest和JohanC)。我尝试使用“plt.figure(figsize=(70,70),dpi=400)”将图片放大,但没有成功。如前所述,您需要确保图片适合您的屏幕。例如,
plt.subplot(figsize=(13,8),dpi=100)
应该可以工作。在这种情况下,您运行的代码与问题中显示的代码不完全相同-建议修改为添加
figsize=(13,8),dpi=100
作为
plt.subplot()
的参数。