Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 should be green. Please provide me a simple example, I couldn't find anything on the web.

like image 983
alwbtc Avatar asked Jan 24 '15 19:01

alwbtc


People also ask

How do I create a threshold line in Matplotlib?

The axhline() function in pyplot module of matplotlib library is used to add a horizontal line across the axis. Parameters: y: Position on Y axis to plot the line, It accepts integers. xmin and xmax: scalar, optional, default: 0/1.


1 Answers

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)
like image 88
Abu Shoeb Avatar answered Sep 29 '22 22:09

Abu Shoeb