擅长:python、mysql、java
<p>你可以编一本颜色字典,在散点图中查找,如下所示</p>
<pre><code>%matplotlib inline
import matplotlib.pyplot as plt
Y = [ 1 , 2 , 3 ,6]
X = [ 1 , 2 , 4 ,5]
vocabulary = [1 , 2 , 3, 0]
my_colors = {1:'red',2:'green',3:'blue'}
for i,j in enumerate(X):
# look for the color based on vocabulary, if not found in vocubulary, then black is returned.
plt.scatter(X[i] , Y[i], color = my_colors.get(vocabulary[i], 'black'))
plt.show()
</code></pre>
<p>结果</p>
<p><a href="https://i.stack.imgur.com/goc1c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goc1c.png" alt="enter image description here"/></a></p>