You can pass either colors, or an array of values that it will interpret as colors itself. We can see that we have a legend with colors but not the variable names. 4 Answers Sorted by: 17 As your traceback tells you, you can't pass a string to the color parameter. Our first attempt to add legends did not work well. Plt.legend(handles=scatter.legend_elements(), Scatter = plt.scatter(df.culmen_length_mm, In legend(), we specify title and handles by extracting legend elements from the plot. In combination, they represent the colorspace. Example lors API List of named colors Example 'Red', 'Green', and 'Blue' are the intensities of those colors. We can try to add legend to the scatterplot colored by a variable, by using legend() function in Matplotlib. Specifying colors Color formats Matplotlib recognizes the following formats to specify a color. Add Color to Scatterplot by variable in Matplotlib Adding legend to Matplotlib scatte plot Note that the scatter plot colored by a variable is missing legend to describe the meaning of the clusters we see. Plt.savefig("scatterplot_point_colored_by_variable_matplotlib_Python.png", We use “c” argument in scatter() function to color data points by species variable in the dataframe.Ĭ=df.species.astype('category').cat.codes)
0 Comments
Leave a Reply. |