Suppose I have a data frame

name = ['A', 'B', 'C'] 
score = [2,4,6] 

I want to create a scatter plot with the following conditions, color the bubble as green if the score is greater than 3 and red otherwise. I'd also like to label the bubble with its respective name.

I'm only able to create a scatter plot with the bubble having the respective name.


1 Answer 1


This type of scatter plot is best performed in seaborn for Python.

# example from: https://python-graph-gallery.com/?s=scatter
# library & dataset
import seaborn as sns
df = sns.load_dataset('iris')

# Use the 'hue' argument to provide a factor variable
sns.lmplot( x="sepal_length", y="sepal_width", data=df, fit_reg=False, hue='species', legend=False)

# Move the legend to an empty part of the plot
plt.legend(loc='lower right')

The keyword hue will designate which variable is the one which is used for labeling the data points. Also, have a look at the link provided for more examples.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.