Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotly express heatmap cell size

Tags:

python

plotly

How can i change the size of cells in a plotly express heatmap? I would need bigger cells

import plotly.express as px
fig1 = px.imshow(df[col],color_continuous_scale='Greens')
fig1.layout.yaxis.type = 'category'
fig1.layout.xaxis.type = 'category'
fig1.layout.yaxis.tickmode = 'linear'
fig1.layout.xaxis.tickmode = 'linear'
fig1.layout.xaxis.tickangle = 65
fig1.layout.autosize = True
fig1.layout.height = 500
fig1.layout.width = 500

fig1.show()

Result (very narrow)

enter image description here

like image 767
Vince Avatar asked May 16 '26 11:05

Vince


1 Answers

'px' may not make it square due to the color bar, so why not use 'go'?

import plotly.graph_objects as go

fig = go.Figure(data=go.Heatmap(
                    z=[[1, 20, 30],
                      [20, 1, 60],
                      [30, 60, 1]]))

fig.show()

enter image description here

Set the graph size.

fig.layout.height = 500
fig.layout.width = 500

enter image description here

Examples at px

import plotly.express as px
data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
fig = px.imshow(data,
                labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
                x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
                y=['Morning', 'Afternoon', 'Evening']
               )
fig.update_xaxes(side="top")

fig.layout.height = 500
fig.layout.width = 500

fig.show()

enter image description here

like image 148
r-beginners Avatar answered May 19 '26 01:05

r-beginners