Is there a way to create hierarchical axis labels for a python plotly heatmap?

Viewed 201

I've been trying to create hierarchical labels in a python plotly heatmap but there doesn't seem to be a way to do so. Can anyone please provide any ideas if there is a way to do this? As an example, please check the graph in the image link below. I am using the create_annotated_heatmap function in plotly figure factory library for my heatmap.

For illustration, I want to do something similar to the graph in the image link below but just replace the bar plots with a heatmap.

Example

As an example, see this script below where I am using some sample data to create a heatmap. In this example, the teams belong to different countries shown in the y1 dictionary and I want to show the country to which the team belongs to as a hierarchical label to the team name along the y-axis.

import plotly.figure_factory as ff

z = [[.1, .3, .5],
     [1.0, .8, .6],
     [.6, .4, .2],
     [.4, .1, .6],
     [.9, .4, .4],
     [.3, .2, .2],
     [.6, .4, .2]]

y = ['Team A', 'Team B', 'Team C','Team D', 'Team E', 'Team F','Team G']
x = ['Game Three', 'Game Two', 'Game One']

y1 = {'USA': 'Team A', 
      'UK':'Team B', 
      'USA': 'Team C',
      'UK': 'Team D', 
      'UK': 'Team E', 
      'Canada': 'Team F',
      'Canada': 'Team G'}

zmin = 0
zmax = 1

green = '#00d000'
red = '#d00000'
grey = '#bbbbbb'

fig = ff.create_annotated_heatmap(
            z=z,
            y=y,
            x=x,
            colorscale=[[0.0, red], [0.5, grey], [1.0, green]],
            xgap=2,
            ygap=2,
            zmin=zmin,
            zmax=zmax
        )

fig.show()
0 Answers
Related