Pyplot - change color of line if data is less than zero?

前端 未结 3 454
耶瑟儿~
耶瑟儿~ 2020-12-28 22:24

I am trying to figure out if there is anything built into pyplot that will change the color of my line depending on whether or not the data is negative or positive. For exam

3条回答
  •  一个人的身影
    2020-12-28 23:04

    If you use a scatter plot you can give each point a different color:

    x = range(1)
    x = range(10)
    y = [i - 5 for i in x]
    c = [i < 0 for i in y]
    plt.scatter(x, y, c=c, s=80)
    

    enter image description here

提交回复
热议问题