需要使用seaborn创建热力图,但似乎无法理解如何操作。
每个组件(行)都需要在热力图上显示。在左侧(y轴)应显示每个组件的EID。由于有很多组件,因此仅标记每10-20个组件中的1个即可。x轴应显示数据集的5个列:ROTATION1 ROTATION2 ROTATION3 ROTATION4 ROTATION5。这里的EXTRA列对于热力图不相关。
热力图应表示的值为“ROT”、“STILL”、“FLIP”或介于160-180之间且间隔为2的任何数字(如160、162、164等)。
某些行在ROTATION1-ROTATION5的所有列中都为空,但仍应在热力图中包含这些组件(并且不为它们显示颜色)。
我尝试过的内容:
每个组件(行)都需要在热力图上显示。在左侧(y轴)应显示每个组件的EID。由于有很多组件,因此仅标记每10-20个组件中的1个即可。x轴应显示数据集的5个列:ROTATION1 ROTATION2 ROTATION3 ROTATION4 ROTATION5。这里的EXTRA列对于热力图不相关。
热力图应表示的值为“ROT”、“STILL”、“FLIP”或介于160-180之间且间隔为2的任何数字(如160、162、164等)。
某些行在ROTATION1-ROTATION5的所有列中都为空,但仍应在热力图中包含这些组件(并且不为它们显示颜色)。
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| EID | EXTRA | ROTATION1 | ROTATION2 | ROTATION3 | ROTATION4 | ROTATION5 |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| AB1178 | POS | FLIP | | STILL | 172 | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| EC8361 | NEG | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| QS7229 | POS | | | 160 | | ROT |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| SE0447 | NEG | ROT | STILL | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| YT5489 | NEG | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| SZ2548 | NEG | 164 | | | FLIP | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| OT6892 | POS | FLIP | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| PL3811 | POS | | | | STILL | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| WQ0893 | POS | | | ROT | | 170 |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| TY3551 | NEG | 160 | FLIP | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| PC6466 | POS | | 180 | 176 | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| YH5912 | POS | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| BK6245 | NEG | | | | STILL | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| GQ2081 | POS | | | | 162 | FLIP |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| GF8633 | NEG | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| FJ4895 | NEG | | 174 | | ROT | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| YD2504 | POS | | | | | 162 |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| RF3510 | POS | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| PN6167 | NEG | | 168 | FLIP | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| RB9747 | POS | FLIP | | STILL | 178 | STILL |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| BQ0841 | NEG | | ROT | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| HJ5187 | NEG | | | | | |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| BP2359 | POS | 168 | STILL | | | ROT |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
| FN6198 | POS | ROT | | | 172 | FLIP |
+--------+-------+-----------+-----------+-----------+-----------+-----------+
我尝试过的内容:
df = pd.read_csv('DATA.csv')
df = pd.DataFrame(df, columns = ['EID', 'ROTATION1','ROTATION2', 'ROTATION3', 'ROTATION4', 'ROTATION5'])
in_range = list(range(160,181, 2))
direction = ['ROT', 'FLIP', 'STILL']
elements = direction + ([str(num) for num in num_range])
sensing = sns.load_dataset("df")
sensing = sensing.pivot("EID", ['EID', 'ROTATION1','ROTATION2', 'ROTATION3', 'ROTATION4', 'ROTATION5'], elements)
heatmap = sns.heatmap(sensing)
这段代码无法工作,我认为“x-axis”元素应该以列的形式而不是多行出现。如果有人能告诉我如何解决这个问题就太好了!
期望的结果:
一个热图,右侧带有颜色图例栏,其中包含ROT
STILL
FLIP
和160-180之间以2为间隔的数字,如果可能的话按照这个顺序排列。
如前所述,左侧的y轴应该是EID
,但实际数据集有大约200行,因此每10或20个代表一个即可。
热图中应该有5列,每一列分别代表ROTATION1
到ROTATION5
。
我经验不足,只需要一点帮助。
使用Python2.7和PANDAS 0.24.2以及seaborn 0.9.1