如何在 matplotlib 中创建直立的垂直方向文本?
How to create upright vertical oriented text in matplotlib?
用rotation='vertical'
在Matplotlib中创建一个旋转90度的Text对象很容易,像这样
但我想创建这样的文本对象
怎么办?
您可以使用 '\n'.join(my_string)
在字符串 (my_string
) 的每个字符之间插入换行符 (\n
)。
如果您还想删除 -
符号(这在您的问题中暗示),您可以使用 .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()
用rotation='vertical'
在Matplotlib中创建一个旋转90度的Text对象很容易,像这样
但我想创建这样的文本对象
怎么办?
您可以使用 '\n'.join(my_string)
在字符串 (my_string
) 的每个字符之间插入换行符 (\n
)。
如果您还想删除 -
符号(这在您的问题中暗示),您可以使用 .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()