【发布时间】:2016-12-05 04:30:57
【问题描述】:
我无法在 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()
目前的地块如下所示
【问题讨论】:
-
让宽度变窄?
-
啊,正是我需要的,谢谢 :)
-
您应该发布自己问题的答案并接受(系统允许时)。
标签: python matplotlib bar-chart