Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I want to plot empty the circles in y vs x plot and I found a nice answer here I wanted to ask if I can set an edge color according to these values of a third array. I modified this code as follows, but as required, I can only pass color and values to the edge color:

import matplotlib.pyplot as plt 

import numpy as np 

x = np.random.randn(60) 

y = np.random.randn(60)

z = np.random.randn(60)

plt.scatter(x, y, s=80, facecolors='none', edgecolors=z)

1 Answer

0 votes
by (36.8k points)

Here are the 2 ideas:

# define some condition for colors:

colors = ['red' if a < 0 else 'blue' for a in z ]

plt.scatter(x, y, s=80, facecolors='none', edgecolors=colors)

# get colors directly from colormap

plt.scatter(x, y, s=80, facecolors='none', edgecolors=plt.cm.viridis(z))

 Want to be a master in Data Science? Enroll in this Data Science Courses

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...