Hey, don’t know what’ wrong with your code but here is the one I use to create heatmap.
I swap all lines in order to have a classical cross-correlation matrix
class GraphBuilder:
def __init__(self):
pass
@classmethod
def heatmap_displayer(cls, time, freq, assets):
def swap_list(list_to_swap):
def swap_two_cols(l, el1, el2):
stock_el = l[el1]
l[el1] = l[el2]
l[el2] = stock_el
return l
list_copy = list_to_swap.copy()
for i in range(0, int(len(list_copy) / 2)):
swap_two_cols(list_copy, i, len(list_copy) - 1 - i)
return list_copy
title = 'Cross-Correlation Matrix'
id_graph = 'Cross_co_matrix'
cross_corr_matrix = GetDataFromApi.get_data_for_cross_co_matrix(time, freq, False, assets)['cross_correlation_matrix']
# swap to format the matrix for dash heatmap, where first cell is bottom left instead of top left for conventional matrices
data = [{
'z': swap_list(cross_corr_matrix),
'x': assets,
'y': swap_list(assets),
'type': 'heatmap',
'text': cross_corr_matrix
}]
return cls.build_graph(data, title, id_graph)
@staticmethod
def build_graph(data, title, id_graph):
colors = {
'background': '#FE8000',
'text': '#F3F3F3',
'font': '#9E9A1A'
}
figure = go.Figure(
data=data,
layout=go.Layout(
title=title,
# titlefont=dict(color=colors['text']),
plot_bgcolor='whitesmoke',
showlegend=True,
paper_bgcolor=colors['background'], # contour du graph
font={'color': colors['text']} # couleur du texte du graph
)
)
return [dcc.Graph(
figure=figure,
style={'display': 'block'},
id=id_graph
)]
Note that this is in the controleur part of an MVC app, the line
cross_corr_matrix = GetDataFromApi.get_data_for_cross_co_matrix(time, freq, False, assets)['cross_correlation_matrix']
is returning something like :
[[1.0, 0.5090724891692849, 0.31183837298901446],
[0.5090724891692849, 1.0, 0.2677353735604394],
[0.31183837298901446, 0.2677353735604394, 1.0]]