timday
timday

Reputation: 24892

Why does my plotly heatmap render a line chart instead?

I'm using plotly 3.6.1, because that's what Debian 10 ("buster") has (the current "stable" version of Debian).

The documentation suggests creating a heatmap should be as simple as this:

#!/usr/bin/env python3

import plotly
import plotly.figure_factory

z=[
    [0.0,1.0,2.0],
    [1.0,1.0,1.0],
    [2.0,1.0,0.0]
]

a=[
    ['AD','BD','CD'],
    ['AE','BE','CE'],
    ['AF','BF','CF']
]

x=['A','B','C']
y=['D','E','F']

fig=plotly.figure_factory.create_annotated_heatmap(z,x=x,y=y,annotation_text=a)

plotly.offline.plot(fig,filename='heatmap.html',auto_open=False)

However, what that actually gets me when the html file is displayed is:

Output

Which, while it has a grid of the supplied cell annotations and labelled the axes, seems to be under the mistaken impression it's a line chart of some sort.

How can I fix this?

I'm successfully using Plotly for other chart types (Scatter and Sunburst) without any issues. This is the first time I've tried using a figure_factory though, because that generally seems to be described as the easiest way to get a heatmap with cell annotations (which is what I want). I've only ever used the offline style of rendering to an HTML file.

The above code is just in an executable heatmap.py file, executed by ./heatmap.py and then the output viewed in whatever version of Firefox is standard in that Debian release.

Upvotes: 1

Views: 207

Answers (1)

JimCircadian
JimCircadian

Reputation: 171

I've copied into a script and tried your code and it provides an adequate heatmap for the data provided!

I would check that you were definitely using a fresh session in a fresh environment. Did you copy your code from a notebook kernel for example?

Certainly it should work, so if you copy that code directly into an executable file, give it a run and let me know how you get on, I hope you'll be happily surprised :-)

Best of luck!

Upvotes: 1

Related Questions