Matplotlib:如何在酒吧之间获得空间?

Tom*_*Tom 9 python matplotlib

您好我已经开始使用matplotlib并一直在尝试调整网站上的示例代码以满足我的需求.我有下面的代码,我想要的除了每组中的第3个栏与第一组下一个栏重叠.互联网不足以添加图片,但任何帮助都会很棒,如果你能解释我的错误是什么,将不胜感激.

谢谢,汤姆

"""
Bar chart demo with pairs of bars grouped for easy comparison.
"""
import numpy as np
import matplotlib.pyplot as plt


n_groups = 3

means_e1 = (20, 35, 30)
std_e1 = (2, 3, 4)

means_e2 = (25, 32, 34)
std_e2 = (3, 5, 2)

means_e3 = (5, 2, 4)
std_e3 = (0.3, 0.5, 0.2)

fig, ax = plt.subplots()

index = np.arange(n_groups)
bar_width = 0.35

opacity = 0.4
error_config = {'ecolor': '0.3'}

rects1 = plt.bar(index , means_e1, bar_width,
                 alpha=opacity,
                 color='b',
                 yerr=std_e1,
                 error_kw=error_config,
                 label='Main')

rects2 = plt.bar(index + bar_width + 0.1, means_e2, bar_width,
                 alpha=opacity,
                 color='r',
                 yerr=std_e2,
                 error_kw=error_config,
                 label='e2')

rects3 = plt.bar(index + bar_width + bar_width + 0.2, means_e3, bar_width,
                 alpha=opacity,
                 color='g',
                 yerr=std_e3,
                 error_kw=error_config,
                 label='e3')

plt.xlabel('Dataset type used')
plt.ylabel('Percentage of reads joined after normalisation to 1 million reads')
plt.title('Application of Thimble on datasets, showing the ability of each stitcher option.')
plt.xticks(index + bar_width + bar_width, ('1', '2', '3'))
plt.legend()

plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)

Sha*_*wal 9

bar_width + bar_width + 0.20.9.现在你添加另一个bar_width(0.35)的条形图,所以总体而言1.25,大于1.由于1是索引后续点之间的距离,因此您有重叠.

你可以增加index(index = np.arange(0, n_groups * 2, 2))之间的距离,或者将条宽减小到更小的值0.2.