Python 3 - matplitlib text inside vertical line

matplotlib, python, python-3.x

Solution

This isn't a solution but more of a workaround really. You could try setting the background colour for the text or adding a bounding box to it with a specific colour which will eclipse the line. This will make the text appear inline.

You would implement this like so:

plt.text(0.5, 0.5, 'Some Text', ha='center', va='center',rotation='vertical', backgroundcolor='white')

and

plt.text(0.5, 0.5, 'Some Text', ha='center', va='center',rotation='vertical', bbox={'facecolor':'white', 'pad':5})

Of course a problem arises when this line is being overlaid on a histogram of a different colour and you would then have to match the colour of background or box to the histogram. This would display something like so:

Problem

I am trying to use `matplotlib` from Python 3 to achieve something like the image shown below: Similar question has been asked here but accepted answer is not sufficient for my need. I need to add text in the middle of dotted line (which I can plot with `plt.axvline()` function). Here is what I tried ``` import matplotlib.pylab as plt plt.hist(some_data) plt.axvline(0.5, color='k', linestyle='--') plt.text(0.5, 0.5, 'Some Text', ha='center', va='center',rotation='vertical') plt.show() ``` If I can put this text in the middle of dotted line, it will be great.

Original source

Related problems