How to create a matplotlib bar chart with a threshold line?

前端 未结 2 1856
清酒与你
清酒与你 2021-02-04 06:46

I\'d like to know how to create a matplotlib bar chart with a threshold line, the part of bars above threshold line should have red color, and the parts below the threshold line

2条回答
  •  梦毁少年i
    2021-02-04 07:41

    You can simply use axhline like this. See this documentation

    # For your case
    plt.axhline(y=threshold,linewidth=1, color='k')
    
    # Another example - You can also define xmin and xmax
    plt.axhline(y=5, xmin=0.5, xmax=3.5)
    

提交回复
热议问题