Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: Can I interrupt an `axhline` with text?

In a plot, I would like to draw an axhline in a particular plot which is annotated by its value, a bit like the contour plot example here. E.g. looking something like: --------- 0.13 -----------.

Is this possible in matplotlib?

like image 874
Mark van der Wilk Avatar asked Jan 29 '17 19:01

Mark van der Wilk


1 Answers

You can create a normal text object at the center point of the line and then set the background color to the color of the axes so that the horizontal line is not visible behind the text.

plt.axhline(linewidth=4, y=0.5, color='red')

plt.text(0.5, 0.5, 'text', fontsize=30, va='center', ha='center', backgroundcolor='w')

enter image description here

like image 179
Suever Avatar answered Oct 09 '22 00:10

Suever