使用seaborn为下面的代码段生成的散点图如下所示。
ax = sns.scatterplot(x="Param_1",
y="Param_2",
hue="Process", style='Item', data=df,
s=30, legend='full')

我想去掉圆圈中的颜色图例(用于进程),因为圆圈也表示项目'One‘的数据。什么是最好的方式来呈现过程中的颜色图例,而不会与用于项目的形状产生差异。
发布于 2020-07-17 20:13:23
您可以创建所谓的proxy artists并将其用作图例符号。
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig,(ax1,ax2) = plt.subplots(ncols=2)
tips = sns.load_dataset("tips")
hue = "day"
style = "time"
sns.scatterplot(x="total_bill", y="tip", hue=hue, style=style, data=tips, ax=ax1)
ax1.set_title("Default Legend")
sns.scatterplot(x="total_bill", y="tip", hue=hue, style=style, data=tips, ax=ax2)
ax2.set_title("Custom Legend")
handles, labels = ax2.get_legend_handles_labels()
for i,label in enumerate(labels):
if label == hue:
continue
if label == style:
break
handles[i] = mpatches.Patch(color=handles[i].get_fc()[0])
ax2.legend(handles, labels)

https://stackoverflow.com/questions/62952329
复制相似问题