Reputation: 111
I have a RandomForestRegressor()
plot with some important metrics (RMSE, MAE, and MAPE). I have the plot already but I need these metrics in a text box placed just outside of the plot. Here is what it looks like:
sn.set_style('dark')
# plot the model
plot = sn.scatterplot(plant_target, predicted_values_plant_1)
plot.set(xlabel='Given', ylabel='Prediction',title='Usine Random Forest Cross Validation (rain + debit + sierra)')
# generate and graph y = x line
x_plot = np.linspace(0,600,600)
y_plot = x_plot
plt.plot(x_plot, y_plot, color='r')
print('RMSE: '+ str(rmse_plant_1))
print('MAE: '+ str(mae_plant_1))
print('MAPE: '+ str(smape_score_plant_1))
Output:
How do I create a text box to add these metrics just to the right of the plot?
Upvotes: 1
Views: 5123
Reputation: 831
Use plt.text()
, as found in the docs. For example:
import numpy as np
import seaborn as sn
plant_target, predicted_values_plant_1 = [100,200,300,400,500],[100,300,400,400,500]
rmse_plant_1 = 0.7
mae_plant_1 = 0.8
smape_score_plant_1 = 0.9
sn.set_style('dark')
# plot the model
plot = sn.scatterplot(x=plant_target, y=predicted_values_plant_1)
plot.set(xlabel='Given', ylabel='Prediction',title='Usine Random Forest Cross Validation (rain + debit + sierra)')
# generate and graph y = x line
x_plot = np.linspace(0,600,600)
y_plot = x_plot
# *** ADDING TEXT HERE ***
metrics = 'RMSE: '+ str(rmse_plant_1) + '\n' + 'MAE: '+ str(mae_plant_1) + '\n' + 'MAPE: '+ str(smape_score_plant_1)
plt.text(400, 100, metrics)
plt.plot(x_plot, y_plot, color='r')
Upvotes: 1