我有一个 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)