给定熊猫数据框的极地热图

时间:2020-07-23 10:09:19

标签: python pandas heatmap polar-coordinates

这里的新手-我正在尝试绘制与熊猫数据帧值相对应的极坐标热图。数据帧索引和列均为浮点数,分别代表角度和半径。

例如:

# hm.tail()
#               -15.0     -14.0     -13.0  ...      8.0       9.0       10.0
# dswe                                    ...                              
# 1.374447  0.008586  0.000715  0.018245  ...  0.012521  0.008586  0.019676
# 1.767146  0.000000  0.000000  0.004293  ... -0.000715  0.013594  0.000000
# 2.159845  0.004293  0.013237  0.006082  ...  0.000000  0.000000  0.004293
# 2.552544  0.004293  0.004293  0.000715  ...  0.000358  0.004293  0.000000
# 2.945243  0.000358  0.000000  0.002146  ...  0.003935  0.001789  0.000000

我仅设法分散了值并相应地对它们进行了颜色/大小调整:

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(); 
ax = fig.add_subplot(111, projection='polar'); 
for radius in hm.columns: 
    angle = hm.index.values
    r = [radius]*len(angle)
    vals = hm[radius].values
    ax.scatter(angle, r, s=vals*20, c=vals, cmap='Blues')
ax.set_rticks(np.arange(hm.columns[0], hm.columns[-1]+1, 5));

我敢肯定,还有一种更优雅的方法,可以为每一对行/列返回彩色图块。

任何提示将不胜感激!

0 个答案:

没有答案
相关问题