how can different points be plotted in different colors in matplotlib when the colors are named and not referred to by number? 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. 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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.