简体   繁体   English

在matplotlib中按名称绘制具有不同颜色的点

[英]plotting points with different colors by name in matplotlib

how can different points be plotted in different colors in matplotlib when the colors are named and not referred to by number? 当颜色被命名而不用数字引用时,如何在matplotlib中以不同的颜色绘制不同的点? eg 例如

import matplotlib.pylab as plt
# this fails
plt.plot([1,2,3],[4,5,6],c=["r", "k", "b"]) 

c only takes numeric values. c仅采用数值。 is there a way to pass it names of colors instead? 有没有办法通过它传递颜色名称呢?

我认为您需要plt.scatter ,在这种情况下,代码可以正常工作:

plt.scatter([1,2,3],[4,5,6],c=["r", "k", "b"]) 

Try this: 尝试这个:

import matplotlib.pylab as plt
xx = [1, 2, 3]
yy = [4, 5, 6]
colors = ['r', 'k', 'b']
for ii in range(len(xx)):
    plt.plot(xx[ii], yy[ii], 'o', color=colors[ii])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM