答案 0 :(得分:3)
您可以使用'\n'.join(my_string)
在字符串(\n
)的每个字符之间插入换行符(my_string
)。
如果您还想去除-
符号(在您的问题中暗示),则可以使用.replace()
函数将其删除。
请考虑以下内容:
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()