0

I am using yellowbrick to generate my learning curve. How can I change the location of my legend? I have tried the following with no luck:

plt.legend(loc="upper left")

from yellowbrick.model_selection import (
    learning_curve,
    validation_curve,
    cv_scores)
plt.rcParams['figure.figsize'] = [10, 5]

plt.legend(loc="upper left")

#plt.gca().set_ylim(bottom=0.5) # set the y axis lower bound

fig2 = plt.gcf()

learning_curve(
    estimator=mlp_new,
    X=x_train,
    y=y_train,
    cv=4,
    train_sizes=np.linspace(0.1,1.0,5),
    n_jobs=1,
    random_state=0,
    scoring='r2',
   )
#ax.set_ylabel("custom x label")
plt.show()
plt.draw()
fig2.savefig('for DNN.jpeg',bbox_inches='tight', dpi=600)
z987
  • 1
  • 2
  • Can you try fig2.legend(loc='upper left') ? – S_Crespo Jun 13 '23 at 11:29
  • @S_Crespo it is not working. Thanks. – z987 Jun 13 '23 at 11:34
  • From the yellowbrick doc here https://www.scikit-yb.org/en/latest/_modules/yellowbrick/model_selection/learning_curve.html#LearningCurve.finalize, I'd try to use the finalize() fonction at the end of the code (instead of plt show() / plt.draw()) and pass a "legend" argument into it. Can't help you more since I don't know yellowbrick but it seems to use plt under the hood, so maybe an argument legend={'loc': 'upper left'} could work ? Or legend={'loc': 1} (choose the digit according to the position you want) – S_Crespo Jun 13 '23 at 12:06

0 Answers0