a | b/openomics/visualization/heatmat.py | ||
---|---|---|---|
1 | import pandas as pd |
||
2 | import plotly.graph_objects as go |
||
3 | |||
4 | |||
5 | def heatmap(table, file_output=None, title=None, autosize=True, width=800, height=1000): |
||
6 | """ |
||
7 | Args: |
||
8 | table: |
||
9 | file_output: |
||
10 | title: |
||
11 | autosize: |
||
12 | width: |
||
13 | height: |
||
14 | """ |
||
15 | if type(table.columns) == pd.MultiIndex: |
||
16 | columns = table.columns.to_series().apply(lambda x: '{0}-{1}'.format(*x)) |
||
17 | else: |
||
18 | columns = table.columns |
||
19 | fig = go.Figure(data=go.Heatmap( |
||
20 | z=table, |
||
21 | x=columns, |
||
22 | y=table.index, |
||
23 | hoverongaps=False, )) |
||
24 | fig.update_layout( |
||
25 | title=title, |
||
26 | autosize=autosize, |
||
27 | width=width, |
||
28 | height=height, |
||
29 | ) |
||
30 | if file_output: |
||
31 | fig.write_image(file_output) |
||
32 | |||
33 | return fig |