首页 > 解决方案 > Seaborn 密度图隐藏散点图

问题描述

我想用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)

标签: pythonmatplotlibplotseaborn

解决方案


尝试:


ax.scatter(df['sepal_width'], df['sepal_length'], s = 10, zorder=2)


推荐阅读