-1

I'm creating a Dash application with a few heatmaps through the px.imshow command. Now all of them have their own colorbar whick makes the figures much smaller than they could be. Therefore, I'd like to remove the colorbars from the individual figures (I know how to do this) and then just add a new figure with only a colorbar (provided with the min and max) All individual plots also have the same min and max.

So, how to make a plotly figure with only a colorbar in it?

Derek O
  • 16,770
  • 4
  • 24
  • 43
debsim
  • 582
  • 4
  • 19
  • Why not just removing the colorbar for all traces except for one ? – EricLavault Aug 23 '23 at 19:05
  • Because having a colorbar changes the dimensions of the actual plot, if only one of the figures has one then this plot will look differently form the others – debsim Aug 24 '23 at 09:14
  • Is it a requirement for you to have one figure per heatmap ? You could just create one figure (one plot) with multiple traces in it. Then it would just be a matter of setting the proper attributes. – EricLavault Aug 24 '23 at 10:27
  • That was my initial approach indeed but it would make much more sense layout wise to separate them so there can be some text and other things between them. I'm also using xarray's and leveraging its automatic labeling. This seems to be only supported with px.imshow and not with go.heatmap. In matplotlib this is easy to do (https://stackoverflow.com/questions/16595138/standalone-colorbar) So i was hoping there's a plotly way as well. – debsim Aug 24 '23 at 10:36
  • I couldn't make my suggestion fit in a comment, so I provided an answer. Note that px.imshow uses go.heatmap (or go.Image) under the hood, so what is possible with imshow is necessarily possible with go.Heatmap. – EricLavault Aug 24 '23 at 10:40

1 Answers1

0

Instead of creating one figure per heatmap, you could just create one figure (one plot) with multiple traces in it. Then it would just be a matter of setting the proper attributes, that is : zmin and zmax (min,max of all heatmaps), and showscale.

For example :

z0 = np.arange(12**2).reshape((12, 12))
z1 = np.arange(15**2).reshape((15, 15))
z2 = np.arange(20**2).reshape((20, 20))

fig = make_subplots(rows=1, cols=3)

fig.add_heatmap(z=z0, row=1, col=1, zmin=0, zmax=20**2, showscale=True)
fig.add_heatmap(z=z1, row=1, col=2, showscale=False)
fig.add_heatmap(z=z2, row=1, col=3, showscale=False)

fig.show()
EricLavault
  • 12,130
  • 3
  • 23
  • 45