gpt4 book ai didi

python - 如何在 matplotlib 中创建直立的垂直方向文本?

转载 作者:太空宇宙 更新时间:2023-11-04 00:10:03 25 4
gpt4 key购买 nike

使用 rotation='vertical' 在 Matplotlib 中创建一个旋转 90 度的文本对象很容易,就像这样 enter image description here

但我想创建这样的文本对象 enter image description here

如何?

最佳答案

您可以使用 '\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()

enter image description here

关于python - 如何在 matplotlib 中创建直立的垂直方向文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52832767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com