Seaborn密度图隐藏散点图

2024-05-13 20:36:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用seaborn绘制一个密度图,然后在该散点图上绘制数据,但是密度图隐藏了散点图的点。如何使点位于密度图上方

#!/usr/bin/env python3

import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset('iris')

fig = plt.figure() 
ax = fig.add_subplot(111)

sns.kdeplot(df['sepal_width'], df['sepal_length'], ax = ax, bw = 0.4, cmap = 'Reds')
ax.scatter(df['sepal_width'], df['sepal_length'], s = 10)

fig.savefig('plot.pdf', bbox_inches='tight', dpi = 300)

Tags: 数据importdfasfig绘制pltseaborn