![]() ![]() We have 6 different sized points to represent the 6 different sized tables. The elements in this scatter plot are different sizes. It’s called the legendelements () method because we want to label the different elements in our scatter plot. Import matplotlib.pyplot as plt import matplotlib.patches as mpatches import numpy as np x = y = categories = np.array() colormap = np.array() plt.scatter(x, y, s=100, c=colormap) pop_a = mpatches.Patch(color='#0b559f', label='Population A') pop_b = mpatches.Patch(color='#89bedc', label='Population B') plt.legend(handles=) plt.title('Nuage de points avec Matplotlib') plt.xlabel('x') plt.ylabel('y') plt.savefig('ScatterPlot_10.png') plt. Fortunately, matplotlib has a scatter plot method we can use. Import matplotlib.pyplot as plt x = y = plt.scatter(x, y, c='coral', label='Class 1') x = y = plt.scatter(x, y, c='lightblue', label='Class 2') plt.legend() plt.title('Nuage de points avec Matplotlib') plt.xlabel('x') plt.ylabel('y') plt.savefig('ScatterPlot_09.png') plt.show() Add a legend to a scatter plot using "Proxy artists" How to add a legend for a scatter plot in matplotlib ?
0 Comments
Leave a Reply. |