我想設定 x 軸粗體的部分文本和其他部分正常字體(非粗體)。我嘗試使用 matplotlib(有效)的 Latex 包裝器,但空格字串xlabel bold(在 xlabel 和粗體之間)消失了。我該如何解決這個問題?
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
#ax.set_xlabel(r'$\mathbf{xlabel bold}$ - ' r'xlable not bold')
ax.set_xlabel(r'$\bf{xlabel bold}$ - ' 'xlable not bold')
plt.show()

uj5u.com熱心網友回復:
干得好:
ax.set_xlabel(r'$\bf{xlabel \ bold}$ - ' 'xlable not bold')
或者你可以使用這個:
ax.set_xlabel(r'$\bf{xlabel}$ $\bf{bold}$ - ' 'xlable not bold')
或者,您可以使用一個簡單的函式:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
def bold_text(text):
new_text = text.replace(' ', r'}$ $\bf{')
new_text = r'$\bf{' new_text r'}$'
return new_text
new_text = bold_text('this is some bold text')
ax.set_xlabel(new_text ' - ' 'xlable not bold')
plt.show()
如需更多選項,您可以訪問:https : //www.overleaf.com/learn/latex/Spacing_in_math_mode
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/324256.html
標籤:Python matplotlib 轴标签
