我想创建一个轴标题,其部分内容以粗体显示。
这是我当前代码的示例:
# Features to plot
features = ['Overall Rating', 'Shooting Rating', 'Creativity Rating', 'Passing Rating',
'Dribbling Rating', 'Defending Rating', 'Pressing Rating', 'Aerial Rating']
# Loop through each feature and create density plots
for i, feature in enumerate(features):
ax = axes[i]
# Draw the density plot using the current feature column from the DataFrame
sns.kdeplot(df[feature], shade=True, color='white', ax=ax)
# Plot marker for df
player_value = df[feature].values[0]
ax.set_title(f'{feature}\n{int(player_value)}', color='#100097', loc='right', fontweight ="bold")
我希望
feature
的文本为正常字体粗细,而 player_value
的文本为粗体字体粗细。
我尝试了各种方法都无济于事:为文本的每个部分创建单独的标题,尝试在
set_title
函数中单独设置字体粗细,等等...
你可以使用 LateX 来实现这一点,使用这种表达方式非常容易:
$\\mathbf{bold text}$"
。在这种情况下,“粗体文本”将显示为粗体。
因此,根据您的情况,添加以下内容:
ax.set_title(f'{feature}\n$\\mathbf{{{int(player_value)}}}$', color='#100097', loc='right')