python matplotlib:使用粗体文本时冒号周围出现奇怪的空格

问题描述 投票:0回答:1

只想生成一个标题中包含日期和时间的绘图,但时间格式为粗体。执行下面的最小示例时,标题中的冒号周围会出现空格。

如何去掉这些空白?

import matplotlib.pyplot as plt
date = '2023/22/12'
time = '19:20:21'
fig, ax = plt.subplots()
plt.title( date + '  ' + r'$\bf{' + time + r'~UTC}$' )
plt.savefig( 'colon_title_test.png' )

python matplotlib latex
1个回答
0
投票

使用

\colon
而不是
:
,如 tex.stackexchange.com 上的回答。

ax.set_title(date + '  ' + r'$\bf{' + time.replace(':', '\colon') + r'~UTC}$')
© www.soinside.com 2019 - 2024. All rights reserved.