![]() ![]() ![]() 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. Earlier we saw a tutorial,how to add colors to data points in a scatter plot made with Matplotlib‘s scatter() function. To plot a scatter in 3D, use the plot method, as the legend does not support Patch3DCollection as is returned by the scatter method of an Axes3D instance. 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" Matplotlib, one of the powerful Python graphics library, has many way to add colors to a scatter plot and specify legend. How to add a legend for a scatter plot in matplotlib ? If you simply plot the lines and call ax. For example, say you have plotted 10 lines, but don't want a legend item to show up for each one.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |