How can I add values to the heatmap below without using figure factory?
I can’t tell in this example (or from documentation) what is actually making the numbers appear in the heatmap cells. Please help!
How can I add values to the heatmap below without using figure factory?
I can’t tell in this example (or from documentation) what is actually making the numbers appear in the heatmap cells. Please help!
Hi @cmedhurs,
it would be easie to answer if you provide the code you used for your plot
Greetings,
Alex
Hi @cmedhurs,
The create_annotated_heatmap
figure factory draws the text using standard plotly annotations (https://plot.ly/python/text-and-annotations/#adding-text-to-data-in-line-and-scatter-plots).
-Jon
nparray=np.array([[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 16, 15, 26, 166, 133, 71, 74],
[ 100, 123, 105, 101, 148, 283, 161],
[ 141, 116, 108, 146, 172, 317, 222],
[ 129, 113, 152, 179, 242, 345, 372],
[ 518, 544, 514, 500, 653, 906, 815],
[ 828, 747, 772, 793, 1121, 1356, 1170],
[ 544, 445, 494, 500, 665, 1068, 873],
[ 261, 213, 291, 260, 348, 604, 531],
[ 253, 202, 188, 241, 300, 351, 383],
[ 323, 284, 314, 410, 455, 403, 400],
[ 602, 681, 780, 1030, 1238, 1047, 913],
[ 855, 1181, 1136, 1334, 1658, 1281, 1172],
[ 626, 822, 857, 1081, 1174, 922, 695],
[ 319, 417, 451, 522, 569, 437, 270],
[ 122, 133, 185, 254, 190, 165, 95],
[ 3, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0]], dtype=np.int16).tolist()
display(nparray)
layout_heatmap = plotly.graph_objs.Layout(
title=(‘Title’),
scene=dict(xaxis=dict(range=[0,6], title=‘Weekday’), yaxis=dict(range=[0, 24],
title=‘Hour’),zaxis=dict(title=‘Visitors’, range=[0, 3000])))
trace = plotly.graph_objs.Heatmap(z=nparray, text=nparray)
data=[trace]
fig = plotly.graph_objs.FigureWidget(data=data, layout=layout_heatmap)
fig.layout.height = 750
fig.layout.width =750
plotly.offline.iplot(fig)
Hi @alexboiboi,
I’ve copied the code below. Thanks in advance for any additional insight!
Hi @jmmease,
Just to reiterate, I do not want to use the create_annotated_heatmap figure factory to annotate the heatmap.
Hi @cmedhurs, it is still not clear why you won’t use figurefactory
since it is doing what you want, as far as i understand it. So I rewrote your code using it.
import plotly.graph_objs as go
from plotly.offline import iplot
import plotly.figure_factory as ff
import numpy as np
visitors_array=np.array([[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 16, 15, 26, 166, 133, 71, 74],
[ 100, 123, 105, 101, 148, 283, 161],
[ 141, 116, 108, 146, 172, 317, 222],
[ 129, 113, 152, 179, 242, 345, 372],
[ 518, 544, 514, 500, 653, 906, 815],
[ 828, 747, 772, 793, 1121, 1356, 1170],
[ 544, 445, 494, 500, 665, 1068, 873],
[ 261, 213, 291, 260, 348, 604, 531],
[ 253, 202, 188, 241, 300, 351, 383],
[ 323, 284, 314, 410, 455, 403, 400],
[ 602, 681, 780, 1030, 1238, 1047, 913],
[ 855, 1181, 1136, 1334, 1658, 1281, 1172],
[ 626, 822, 857, 1081, 1174, 922, 695],
[ 319, 417, 451, 522, 569, 437, 270],
[ 122, 133, 185, 254, 190, 165, 95],
[ 3, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0]], dtype=np.int16)
#display(nparray)
Weekdays_list = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] # Order may be different
Hours_list = ['{:d}AM'.format(i+1) for i in range(12)] + ['{:d}PM'.format(i+1) for i in range(12)]
layout_heatmap = go.Layout(
title=('Number of visitors per Weekday/Hour'),
xaxis=dict(title='Weekday'),
yaxis=dict(title='Hour', dtick=1)
)
ff_fig = ff.create_annotated_heatmap(x= Weekdays_list, y=Hours_list, z=visitors_array, showscale = True)
fig = go.FigureWidget(ff_fig)
fig.layout=layout_heatmap
fig.layout.annotations = ff_fig.layout.annotations
fig.data[0].colorbar = dict(title='Number of visitors', titleside = 'right')
iplot(fig)
Not to highjack/revive this thread unnecessarily (sorry if i am), but i’m having issues getting figure factory to work with Flask - it just returns an empty figure. Is there any reason figure factory wouldn’t work as far as the json compared to a go.heatmap?