matplotlib - How to add two labels to one scatterplot

MAA

I've a single scatter plot. However, I've differentiated the points using another column (Playoffs - {0, 1}).

Now how can I give the 0 values for Playoffs a label and the 1 values another label?

fig = plt.figure(figsize=(8, 6))
plt.scatter(nba.ptsDiff, nba.W, s=25, c=nba.Playoffs, label='bla')
plt.legend()
plt.show()
Keita Broadwater

Try filtering the playoff value in the columns. Then plot each using a separate plt.scatter command. Finally use lists of the plots and the legend labels in legend.

fig = plt.figure(figsize=(8, 6))
nba1 = nba[nba['Playoffs'] == 1]
nba0 = nba[nba['Playoffs'] == 0]
pla = plt.scatter(nba1.ptsDiff, nba1.W, color='red')
plb = plt.scatter(nba0.ptsDiff, nba0.W, color='blue')

plt.legend([pla, plb], ["Attr A", "Attr B"])

plt.show()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add text labels to a scatterplot?

How to add legend based on color in scatterplot [matplotlib]

How to add two tiers of labels for matplotlib stacked group barplot

matplotlib scatterplot x axis labels

How to add legend labels per plotted column to multiple scatterplot subplots?

How can I add labels inside the points in a scatterplot?

How to add two data sets on one bar graph using matplotlib

How to add additional labels in my plot in matplotlib?

How to add group labels for bar charts in matplotlib?

How to add bar labels using Matplotlib

How to add ggplot legend to scatterplot with two separate dataset lines

How can I add two labels together which one has a "$" in front of the text?

How to affect two labels with one UIStepper

Dygraphs how to implement two labels for one axis

Matplotlib scatterplot error bars two data sets

How to use togglebutton to turn labels in scatterplot on/off

How to rename labels and title in seaborn scatterplot legend?

matplotlib scatterplot - only a few labels are displayed on x axis

matplotlib axis tick labels covered by scatterplot (using spines)

How do I add color as a 3rd dimension to matplotlib scatterplot?

how to add path effect to axis tick labels in matplotlib?

How to add labels and title to matplotlib.pyplot.matshow plot?

How to add (or annotate) value labels (or frequencies) on a matplotlib "histogram" chart

How to add vertically centered labels in bar chart matplotlib

How to add multiple data labels in a bar chart in matplotlib

How to add X and Y group labels to subplots in a matplotlib plot?

How do I add labels for a horizontal bar using matplotlib module?

Is there a way to only show two labels on the x-axis in a scatterplot?

How to scale legend elements down in a scatterplot matplotlib?