我试图有一个图表,表,然后文本显示为一个图形。我试图通过使用一个ax_text对象来简化文本。但是,我不知道如何在ax_text.annotate()函数中加粗一个单词。我试了一下重量=‘粗体’,但这个支撑住了整个字符串。此外,我尝试了ASCII \033[0m &\033][1M,但这不起作用。我可以为每个粗体单词创建一个单独的ax_text对象,但是找出合适的xy坐标是很困难的,因为文本长度可能会改变。
如何从ax_text获得注释调用,使其仅在文本中粗体一个单词?
import pandas as pd
import matplotlib.pyplot as plt
fig, (ax, ax_table, ax_text) = plt.subplots(nrows=3, figsize=(10,8), gridspec_kw=dict(height_ratios=[4,1,1]))
tbl = (ax_table.table(rowLabels=["RowLabel1","RowLabel2", 'RowLabel3'],
colLabels=['ColLabel1', 'ColLabel2', 'ColLabel3'],
cellText=[["1", "2", "3"],
["1", "2", "3"],
["1", "2", "3"]],
cellLoc='center',
loc='center'))
tbl.auto_set_font_size(True)
tbl.set_fontsize(10)
tbl.scale(1,1)
ax_table.axis('off')
text = "This is text. I want the word 'blah' to be Bold."
ax_text.axis('off')
ax_text.annotate(text, wrap=True, xy=(-0.12,1), xycoords='axes fraction', weight='bold', verticalalignment='top')
fig
发布于 2021-10-05 09:16:02
您可以指示matplotlib
使用LaTeX进行文本格式化:https://matplotlib.org/stable/tutorials/text/usetex.html
plt.rc('text', usetex=True)
text = r"This is text. I want the word '\textbf{blah}' to be Bold."
https://stackoverflow.com/questions/69454573
复制相似问题