【发布时间】:2018-10-02 12:11:06
【问题描述】:
我有 2 个独立的绘图功能要组合。
首先是根据密度添加颜色。第二个是跨越散点图及其各自的边缘(我更喜欢左右而不是上下,但我自己可能会得到)
尝试将 z=c 选项添加到组合散点图时出现错误。
from scipy.stats import gaussian_kde
import numpy as np
import matplotlib.pyplot as plt
x = np.random.normal(0,1,500).reshape(-1)
y = x + 0.3*np.random.normal(0,1,500).reshape(-1)
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
plt.scatter(x,y,c=z)
plt.show()
scatter_axes = plt.subplot2grid((3, 3), (1, 0), rowspan=2, colspan=2)
x_hist_axes = plt.subplot2grid((3, 3), (0, 0), colspan=2,
sharex=scatter_axes)
y_hist_axes = plt.subplot2grid((3, 3), (1, 2), rowspan=2,
sharey=scatter_axes)
nbins = 30
scatter_axes.plot(x, y, '.')
x_hist_axes.hist(x, nbins)
y_hist_axes.hist(y,nbins, orientation='horizontal')
plt.show()
如何在子图中获得密度颜色?
【问题讨论】:
标签: python colors histogram scatter