It is easy to create a Text object in Matplotlib rotated 90 degrees with rotation='vertical'
, like this
But I want to create Text objects like this
How?
It is easy to create a Text object in Matplotlib rotated 90 degrees with rotation='vertical'
, like this
But I want to create Text objects like this
How?
You can use '\n'.join(my_string)
to insert newline characters (\n
) between each character of the string (my_string
).
If you also want to strip out the -
symbols (which is implied in your question), you can use the .replace()
function to remove them.
Consider the following:
import matplotlib.pyplot as plt
my_string = '2018-08-11'
fig, ax = plt.subplots(1)
ax.text(0.1, 0.5, my_string, va='center')
ax.text(0.3, 0.5, my_string, rotation=90, va='center')
ax.text(0.5, 0.5, '\n'.join(my_string), va='center')
ax.text(0.7, 0.5, '\n'.join(my_string.replace('-', '')), va='center')
plt.show()