'Easy issue : Display legend in plots based on a color dictionary python

My problem is simple but I can't fix it. I want to display a legend :

Based on my dictionary "color_dict" which defines colors, variables All in red and AML in blue, I want to display a legend. Porblem is, only the first one (All red) appears. I have tried to use color_dict.keys to access the keys of my dictionary but it doesn't seem to work. I don't understand the problem, why would ax.legend(color_dict.keys()) only take the first key/value pair of my dictionary ? How can I fix that?

Thanks for your help

More explainations if needed:

I want to plot the legend with 'All' in red and 'AML' in blue, but these variables are in my dictionary and when I try to access it with .keys in the ax.legend() from python, it only displays the first item as you can see on the picture.

`
l_dtprj2= list(zip(*data_proj2))

color_dict = {'ALL': 'red','AML': 'blue'}

x = l_dtprj2[0]
y= l_dtprj2[1]
colorName = list(df3['labels'])

fig, ax, = plt.subplots()

ax.scatter(x, y, c=df3['labels'].map(color_dict) )

plt.xlabel('Component 1') #x label

plt.ylabel('Component 2') #y label




ax.legend(color_dict.keys())


plt.show()`

My code AND its results (plot)

Here is the type of legend I'd like to have right below on the plot



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source