相关疑难解决方法(0)

Seaborn 条形图图例标签失去颜色

我有一个 seaborn boxplot,当我尝试使用 plt.legend("Strings") 更改标签名称时,它会丢失标签的颜色。我需要在保持颜色编码的同时更改标签,但在搜索答案后我不知道如何执行此操作。

色调图例 1-4 对应于 1 = 对政治非常感兴趣到 4 = 完全不感兴趣。我想将图例色调标签从 1-4 更改为他们对政治的兴趣程度。

我的代码是:

套餐

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)

我不知道如何以更简单的方式创建数据框,所以我这样做了

a1 = {'Reads Newspapers': 0, 'Interest in Politics': 1}
a2 = {'Reads Newspapers': 0, 'Interest in Politics': 2}
a3 = {'Reads Newspapers': 0, 'Interest in Politics': 3}
a4 = {'Reads Newspapers': 0, 'Interest in Politics': 4}
b1 = {'Reads Newspapers': 1, 'Interest in Politics': 1} …
Run Code Online (Sandbox Code Playgroud)

python matplotlib seaborn

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

matplotlib ×1

python ×1

seaborn ×1