我有三种数据分布:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
a = np.load('A.npy')
b = np.load('B.npy')
c = np.load('C.npy')
plt.figure(figsize=(12,4))
plt.subplot(131)
plt.hist2d(a,b,bins=300,norm=LogNorm())
plt.xlabel('A')
plt.ylabel('B')
plt.subplot(132)
plt.hist2d(a,c,bins=300,norm=LogNorm())
plt.xlabel('A')
plt.ylabel('C')
plt.subplot(133)
plt.hist2d(b,c,bins=300,norm=LogNorm())
plt.xlabel('B')
plt.ylabel('C')
plt.show()
有什么想法吗?
答案 0 :(得分:1)
首先,比较容易的部分是绘图:我使用了3次相同的随机数据,缩小了(0..2pi-> 0..2 / 3pi)并移动了(0,2 / 3pi,4 / 3pi ),他们将获得3个大比萨饼部分:
import numpy as np
import matplotlib.pyplot as plt
parts = 3
ax = plt.subplot(111, polar=True)
shrink = 1./parts
for i in range(3):
# beginning and end angle of this part
start = i * 2/parts * np.pi
end = (i + 1) * 2/parts * np.pi
# Generate random data:
N = 10000
r = .5 + np.random.normal(size=N, scale=.2)
theta = (np.pi / 2 + np.random.normal(size=N, scale=.1))
# shift the data counterclockwise so that it fills the n-th part
theta += i * 2.*np.pi / parts
# Histogramming
nr = 50
ntheta = 200
r_edges = np.linspace(0, 1, nr + 1)
theta_edges = np.linspace(start, end, ntheta + 1)
H, _, _ = np.histogram2d(r, theta, [r_edges, theta_edges])
# Plot
Theta, R = np.meshgrid(theta_edges, r_edges)
ax.pcolormesh(Theta, R, H)
plt.show()
现在更困难的部分:您仍然必须将点转换为径向值,我不确定如何为坐标定义此点,因为点具有3维,但您想映射到2d。我希望这会有所帮助!
我的代码基于this 2d heatmap。