Figure_factory.create_annotated_heatmap

Hi,

I want to define my own layout for the create_annotated_heatmap function in python from the plotly.figure_factory class, specifically change the margin so that there is less white space on the screen.

However it doesn’t seem I can do it. Here’s my code. Is there a way for me to do this?

import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.graph_objs as go

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

x = [‘Team A’, ‘Team B’, ‘Team C’]
y = [‘Game Three’, ‘Game Two’, ‘Game One’]

z_text = [[‘Win’, ‘Lose’, ‘Win’],
[‘Lose’, ‘Lose’, ‘Win’],
[‘Win’, ‘Win’, ‘Lose’]]

layout = go.Layout(
autosize=False,
annotations=,
xaxis={
“ticks”: “”,
“side”: “top”
},
yaxis={
“ticks”: ‘’,
“ticksuffix”: ’ ',
},
margin=go.Margin(
l=60,
r=10,
b=0,
t=20,
pad=4
)
)

fig = ff.create_annotated_heatmap(z, x=x, y=y, annotation_text=z_text, colorscale=‘Viridis’)

py.iplot({
“data”: fig,
“layout”: layout
}, filename=‘annotated_heatmap_text’)

Nevermind, figured it out. Just do this:

   fig.layout.margin.update({
        "l": 60,
        "r": 0,
        "b": 10,
        "t": 20,
        "pad": 4
    })
1 Like