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?
In general, to show any text in matplotlib with a vertical orientation, you can add the keyword rotation='vertical' .
MatPlotLib with PythonPlace legend using legend() method and initialize a method. Iterate the legend. get_texts() method to set the horizontal alignment. To display the figure, use show() method.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With