Skip to content

code

python
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")

# 加载钻石数据集


<NolebasePageProperties />




diamonds = sns.load_dataset("diamonds")

# 创建绘图对象并设置布局
f, ax = plt.subplots(figsize=(6.5, 6.5))
sns.despine(f, left=True, bottom=True)

# 定义清晰度排序
clarity_ranking = ["I1", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF"]

# 绘制散点图
sns.scatterplot(x="carat", y="price",
                hue="clarity", size="depth",
                palette="ch:r=-.2,d=.3_r",
                hue_order=clarity_ranking,
                sizes=(1, 8), linewidth=0,
                data=diamonds, ax=ax)

# 显示图像
plt.show()

贡献者

文件历史

Written with