I am trying to visualize this graph with a lineplot, but the legend is not working correctly as you can see in the image below.
The problems are three:
- two rectangles appear in the second and fourth positions
- the legend only show the black, the blue, and the red lines
- the three lines above mentioned do not correspond to those in the code (you can obeserve it in the image)
Did someone face the same problem? Who can help me?
var = 'eta_contraente'
target = 'target_accettazione'
DF = df_pred[[var,'target_accettazione','prediction_ret_1', 'prediction_ret_2', 'prediction_ret_3','prediction_ret_4_no_crawler']]
DF['pred_decili'] = pd.qcut(DF[var], list(np.linspace(0, 1, n)))
fig=plt.figure(figsize=(8, 5))
ax = fig.add_subplot(111)
mean_val = DF.groupby("pred_decili").mean().reset_index()
sns.lineplot(x=mean_val.index, y= target,
data=mean_val, marker='s', color = 'black')
sns.lineplot(x=mean_val.index, y= "prediction_ret_1",
data=mean_val, marker='s', color = 'blue')
sns.lineplot(x=mean_val.index, y= 'prediction_ret_2',
data=mean_val, marker='s', color = 'red')
sns.lineplot(x=mean_val.index, y= "prediction_ret_3",
data=mean_val, marker='s', color = 'yellow')
sns.lineplot(x=mean_val.index, y= 'prediction_ret_4_no_crawler',
data=mean_val, marker='s', color = 'green')
ax.set_xticks(mean_val.index)
ax.set_xticklabels(mean_val[var].round(), rotation = 60)
ax.legend([ 'black line', "blue line", "red line","yellow line","green line" ], loc='lower right', fontsize = 14);
Please, try to suggest which there is a problem in the code, or whether it is due to the version of matplotlib or pandas