使用matplotlib的等高线热覆盖散点图

使用matplotlib的等高线热覆盖散点图,matplotlib,scatter-plot,contour,Matplotlib,Scatter Plot,Contour,我有一个大系列的数据,其中包括>200k的值 目标是显示数据的分布和大致趋势,而不是单个点。我想添加一个等高线热覆盖,与此问题类似,但使用matplotlib,并具有指定等高线数量及其间隔的选项: 我希望这是清楚的。如果没有请告诉我 Seaborn的kdeplot将允许您只打印阴影,而不是打印所有数据点。可以通过指定n_levels参数来调整等高线的数量。对于覆盖jointplot和kdeplot的较小数据集,允许同时显示数据点和等高线。人物美学可以有很大的不同,因此我在下面编译了一些不同的选

我有一个大系列的数据,其中包括>200k的值

目标是显示数据的分布和大致趋势,而不是单个点。我想添加一个等高线热覆盖,与此问题类似,但使用matplotlib,并具有指定等高线数量及其间隔的选项:


我希望这是清楚的。如果没有请告诉我

Seaborn的kdeplot将允许您只打印阴影,而不是打印所有数据点。可以通过指定n_levels参数来调整等高线的数量。对于覆盖jointplot和kdeplot的较小数据集,允许同时显示数据点和等高线。人物美学可以有很大的不同,因此我在下面编译了一些不同的选项。使用ImportanceOfBeingErnest对此的回答生成了带有连接图的子图


seaborn的kdeplot生成的绘图与您示例中的类似。@KRKirov这看起来不错,但有没有办法指定绘制等高线的密度?
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
mean = [0, 0]
cov = [[50, 0], [0, 100]] 
x, y = np.random.multivariate_normal(mean, cov, 5000).T

# For large data sets
plt.subplots(1, 2)
plt.subplot(1, 2, 1)
cmap = sns.cubehelix_palette(as_cmap=True, dark=0, light=1, reverse=True)
a = sns.kdeplot(x, y, n_levels=20, shade=True, cmap=cmap, gridsize=200, cbar=True)
a.set_xlabel('x')
a.set_ylabel('y')
plt.subplot(1, 2, 2)
b = sns.kdeplot(x, y, n_levels=60, shade=True, gridsize=100, cmap="RdBu_r", cbar=True)
b.set_xlabel('x')
b.set_ylabel('y')
# For smaller data sets - jointplot and kdeplot overlayed. 
# Plain overlay
c = (sns.jointplot(x, y, color="g", marker='.').plot_joint(sns.kdeplot, n_levels=20)).set_axis_labels('x', 'y')
# with shade=True
d = (sns.jointplot(x, y, color="g").plot_joint(sns.kdeplot, n_levels=20, shade=True)).set_axis_labels('x', 'y')
# with transparency control, alpha=
e = (sns.jointplot(x, y, color="g", marker='.').plot_joint(sns.kdeplot, n_levels=20, shade=True, alpha=0.5)).set_axis_labels('x', 'y')
# diverging colour palette - blue to red
f = (sns.jointplot(x, y, marker='.').plot_joint(sns.kdeplot, n_levels=20, cmap="RdBu_r")).set_axis_labels('x', 'y')
# diverging colour palette and shade and reg
g = (sns.jointplot(x, y, marker='.', kind='reg').plot_joint(sns.kdeplot, n_levels=20, cmap="RdBu_r")).set_axis_labels('x', 'y')
# diverging colour palette, shade, 
h = (sns.jointplot(x, y).plot_joint(sns.kdeplot, n_levels=20, shade=True, cmap="RdBu_r")).set_axis_labels('x', 'y')