I am making a scatter plot which is made up of dots that can be either open or closed dots, and can be in four different colors. If the dot is open, it will have one label. If it's closed, it will have another label.
I would like a legend where it shows 4 dots of each color side by side on one row corresponding to its label, instead of 1 dot per row with the same label.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(3)
y = np.arange(3)
plt.scatter(x,y, color = 'blue', label = 'potatoes')
plt.scatter(x,y, color = 'green', label = 'potatoes')
plt.scatter(x,y, color = 'red', label = 'potatoes')
plt.scatter(x,y, color = 'magenta', label = 'potatoes')
plt.scatter(x,y, color = 'blue', facecolors='none', label = 'tomatoes')
plt.scatter(x,y, color = 'green', facecolors='none', label = 'tomatoes')
plt.scatter(x,y, color = 'red', facecolors='none', label = 'tomatoes')
plt.scatter(x,y, color = 'magenta', facecolors='none', label = 'tomatoes')
plt.plot(x,y, color = 'blue' , label= "Florida")
plt.plot(x,y, color = 'green' , label= "California")
plt.plot(x,y, color = 'red' , label= "Idaho")
plt.plot(x,y, color = 'magenta' , label= "Montana")
l = plt.legend(handlelength = 0)
llines = l.get_texts()
llines[0].set_color('blue')
llines[1].set_color('green')
llines[2].set_color('red')
llines[3].set_color('magenta')
I would prefer the legend output have the four different color dots next to its label on one row, instead of the label being repeated 4 times with each color dot.
I could change the code to have potatoes and tomatoes just once with a black closed or open dot, but I would prefer it with the four different colored dots on one row if it's possible.