python pyplot颜色_更改matplotlib.pyplot点的颜色

您刚刚犯了一个小的复制粘贴错误。

只是对你的风格的一个评论:在使用颜色列表时,你可以避免这么多的ifs,所以:colors=[red,green,blue,black]

然后:plt.annotate('', xy=(x, y), xytext=(0, 0), color=colors[max(3,label)] , textcoords='offset points')

你的代码必须如此,你总是写elif label=1,这完全没有意义:import matplotlib.pyplot as plt

Y = [ 1 , 2 , 3 ]

X = [ 1 , 2 , 4 ]

vocabulary = [1 , 2 , 3]

plt.scatter(X , Y)

for label, x, y in zip(vocabulary, X, Y):

if(label == 1):

plt.annotate('', xy=(x, y), xytext=(0, 0), color='red' , textcoords='offset points')

elif(label == 2):

plt.annotate('', xy=(x, y), xytext=(0, 0), color='green' , textcoords='offset points')

elif(label == 3):

plt.annotate('', xy=(x, y), xytext=(0, 0), color='blue' , textcoords='offset points')

else :

plt.annotate('', xy=(x, y), xytext=(0, 0), color='black' , textcoords='offset points')

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值