我想创建一个轴标题,其中有一部分是粗体字体.

这是我当前代码的一个示例:

# 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为粗体粗细.

我try 了各种方法,但都无济于事:为每段文本创建单独的标题,try 在set_title函数中分别设置字体宽度,等等.

推荐答案

您可以使用101**来实现这一点,非常容易地使用这样的表达式:$\\bf{bold text}$".在这种情况下,"粗体文本"将显示为粗体.

因此,在您的 case 中,添加以下内容:

ax.set_title(f'{feature}\n$\\bf{{{int(player_value)}}}$', color='#100097', loc='right')

**:关于LaTeX,似乎MathText才是所谓的LaTeX,而不是LaTeX,我稍后会编辑我的问题

Python相关问答推荐

由于NEP 50,向uint 8添加-256的代码是否会在numpy 2中失败?

将jit与numpy linSpace函数一起使用时出错

Django mysql图标不适用于小 case

如何获取TFIDF Transformer中的值?

如何列举Pandigital Prime Set

将JSON对象转换为Dataframe

索引到 torch 张量,沿轴具有可变长度索引

我的字符串搜索算法的平均时间复杂度和最坏时间复杂度是多少?

需要帮助重新调整python fill_between与数据点

可以bcrypts AES—256 GCM加密损坏ZIP文件吗?

使用BeautifulSoup抓取所有链接

在Python中计算连续天数

如何在Python请求中组合多个适配器?

每次查询的流通股数量

Seaborn散点图使用多个不同的标记而不是点

具有不同坐标的tkinter canvs.cocords()和canvs.moveto()

某些值的数值幂和**之间的差异

ValueError:必须在Pandas 中生成聚合值

如何将参数名作为参数传入到函数中?

为什么fizzbuzz在两个数字的条件出现在一个数字的条件之后时不起作用?