温馨提示×

Seaborn手动创建图例的方法是什么

小亿
88
2024-05-17 18:12:14
栏目: 编程语言

在Seaborn中,可以通过使用matplotlibLegend对象来手动创建图例。具体步骤如下:

  1. 导入matplotlib库:
import matplotlib.pyplot as plt
  1. 创建Seaborn图表,并保存返回的Axes对象:
ax = sns.scatterplot(x='x', y='y', data=data)
  1. 使用ax.legend()方法创建图例:
ax.legend(['Label 1', 'Label 2', 'Label 3'])

ax.legend()方法中传入一个包含图例标签的列表,即可手动创建图例。可以根据需要自定义图例的位置、大小、颜色等属性。

0