如何在python中在一个雷达图上绘制多个热图图?

2024-04-23 21:38:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有三种数据分布:

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()

结果如下: enter image description here

现在,我想把雷达图上的三个图都表示成这样:

有什么想法吗?你知道吗


Tags: importnormmatplotlibasnploadpltbins
1条回答
网友
1楼 · 发布于 2024-04-23 21:38:54

首先,更简单的部分,绘图:我使用了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()

enter image description here

现在更难的部分:你仍然需要将你的点转换成径向值,我不知道你如何定义你的坐标,因为一个点有3维,但你想映射到二维。我希望这有帮助!你知道吗

我的代码基于this 2d heatmap。你知道吗

相关问题 更多 >