'\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()
text = '2018-08-11'
,然后将其拆分为单个字符,如chars = [j for i in text.split('-') for j in i]
,然后循环遍历它们并使用plt.text
,其中x
固定,y
值变化。 - Sheldore