我想要使用Matplotlib在同一个条形图中绘制这两个词典:
accuracy_pre = {"Random Forest": rf_accuracy_score, "Logistic Regression": log_accuracy_score, "KNN": knn_accuracy_score}
accuracy_post = {"Random Forest": gs_rf_accuracy_score, "Logistic Regression": gs_logmodel_accuracy_score, "KNN": knn_accuracy_score_iter}
字典值是整数变量。两个字典都具有相同的键,因此总共有6个条,但属于相同键的那些将紧挨着彼此。 我能够创建两个单独的条形图,但我很难将它们合二为一。有人能帮助我吗?
这是我已经拥有的条形图的代码:
X = np.arange(len(accuracy_pre))
plt.bar(X, accuracy_pre.values(), align='center', width=0.5)
plt.xticks(X, accuracy_pre.keys())
plt.title("Accuracy score - before grid search", fontsize=17)
plt.ylim(0, 1)
答案 0 :(得分:2)
I tweaked your code a bit to get the desired plot. Hope this helps!
==