在Matplotlib行中添加阴影效果

时间:2020-05-27 17:12:07

标签: python-3.x matplotlib

我有以下代码绘制精度和召回率:

x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
max_depths = np.linspace(1, 5, 5, endpoint=True)
pre_scores = []
rec_scores = []
for max_depth in max_depths:
    rf = RandomForestClassifier(n_estimators=10, max_depth=max_depth, n_jobs=-1)
    rf.fit(x_train, y_train)
    test_pred = rf.predict(x_test)
    pre = precision_score(y_test, test_pred)
    rec = recall_score(y_test, test_pred)
    pre_scores.append(pre)
    rec_scores.append(rec)

plt.grid(b=True, linestyle='dotted', linewidth=0.7, color='lightgrey')
plt.plot(max_depths, pre_scores, 'b', label='Precision')
plt.plot(max_depths, rec_scores, 'r', label='Recall')
plt.xlabel('Tree depth', fontweight='bold', fontsize=12)
plt.ylabel('Scores (positive class)', fontweight='bold', fontsize=12)
plt.tick_params(width=1.5)
plt.legend(loc='best', frameon=True)
plt.show()
plt.clf()

如何修改线条以使其具有类似于下图的阴影效果(此图像取自here):

enter image description here

谢谢

0 个答案:

没有答案
相关问题