我无法在Python中使用matplotlib生成的条形图中的每3个条之间产生间隙。目前,所有条形都聚集在一起,我的目标是在图形中每3个条形之间有1个条形宽度。我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
N = 3
ind = np.arange(N)
width = 0.35
fig, ax = plt.subplots()
accu = [0.72, 0.99, 0.83]
rects1 = ax.bar(ind, accu, width, color='b')
prec = [0.99, 0.99, 0.81]
rects2 = ax.bar(ind+width, prec, width, color='y')
rec = [0.61, 0.99, 0.99]
rects3 = ax.bar(ind + 2 * width, rec, width, color='r')
ax.set_ylabel('Scores')
ax.set_title('Scores for each algorithm')
ax.set_xticks(ind + 1.5*width)
ax.set_xticklabels(('SVM', 'DecisionTree', 'NaiveBayes'))
ax.legend((rects1[0], rects2[0], rects3[0]), ('Accuracy', 'Precision', 'Recall'))
plt.show()
目前的常设情况如下: