【发布时间】:2021-03-31 00:01:59
【问题描述】:
我想绘制两个二维直方图之间的差异。例如,考虑以下代码:
from numpy import c_
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
n = 100000
x = np.random.standard_normal(n)
y = 3.0 * x + 2.0 * np.random.standard_normal(n)
x1 = np.random.normal(loc=-2, scale=5, size=n)
y1 = (x1)**2 + np.random.standard_normal(n)
plt.figure(1)
h, xedges, yedges, image = plt.hist2d(x,y, bins=50, norm=mcolors.LogNorm(), cmap = plt.cm.rainbow)
plt.figure(2)
h1, xedges1, yedges1, image1 = plt.hist2d(x1,y1, bins=50, norm=mcolors.LogNorm(), cmap = plt.cm.rainbow)
是否可以绘制它们之间的差异?
提前谢谢你。
【问题讨论】:
-
您是否对 bin-to-bin 或 cross-bin 比较感兴趣?
-
制作
bins=(xedges, yedges)并在每次调用plt.hist2d之间保持相同(或使用第二次调用中的第一个边缘),然后你就可以做imshow(h-h1)跨度>
标签: python numpy matplotlib