简体   繁体   中英

Plotly : Heatmap color legend i subplot

I'm working in python with plotly, trying to have two heatmap subplot with a custom legend for each. But here what I see with the following code :

import plotly


fig = plotly.subplots.make_subplots(rows=2, cols=1)

mat = np.array([[1,0],
                [0,1]])


fig.add_trace(go.Heatmap(z=mat, colorscale='Bluered_r'), row=1, col=1)

fig.add_trace(go.Heatmap(z=mat*10, colorscale='Bluered_r'), row=2, col=1)

fig.show()

在此处输入图片说明

you can see that both legend are displayed at the same place.

Thanks for your help!

Just found a solution hidden in the doc using the colorbar argument:

import plotly


fig = plotly.subplots.make_subplots(rows=2, cols=1)

mat = np.array([[1,0],
                [0,1]])


fig.add_trace(go.Heatmap(z=mat, colorscale='Bluered_r',colorbar=dict(y=.8,len=.5)), row=1, col=1)

fig.add_trace(go.Heatmap(z=mat*10, colorscale='Bluered_r',colorbar=dict(y=.2,len=.5)), row=2, col=1)

fig.show()

This would give:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM