How to setup Plotly two horizontal subplots containing heatmaps so that they don't share a colorscale?

荒凉一梦 提交于 2019-12-12 02:18:26

问题


I have two heatmaps. Their values are in totally different scale, so should not share a colorscale. I tried to create a plotly figure w/ two subplots (arranged horizontally) and put each of my heatmaps into one of the subplot. However, the two heatmap shares the same colorscale to the right of the heatmap on the right. The colorscale show two sets of labels overlapped w/ each other. What I'd like to see is that there are two colorscales, one to the right of each heatmap.

My code is below. Anyone seeing a problem here?

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

fig.append_trace(mm, 1, 1)
fig.append_trace(sm, 1, 2)

plotly.offline.iplot(fig)

I have tried to set share_xaxes and share_yaxes to False explicitly. Didn't help.


回答1:


You could specify the x position of the colorbar explicitly, see the example below.

The figure looks better in the notebook, perhaps one should also move the right plot?

import plotly.plotly as py
import plotly.graph_objs as go
import plotly
plotly.offline.init_notebook_mode()

mm = go.Heatmap(
        z=[[1, 20, 30],
           [20, 1, 60],
           [30, 60, 1]],
        colorbar = dict(x=0.45), 
    colorscale='Viridis'
    )
sm = go.Heatmap(
        z=[[1, 2, 3],
           [2, 1, 6],
           [3, 6, 1]]
    )
fig = plotly.tools.make_subplots(rows=1, cols=2)
fig.append_trace(mm, 1, 1)
fig.append_trace(sm, 1, 2)

plotly.offline.iplot(fig)


来源:https://stackoverflow.com/questions/42312634/how-to-setup-plotly-two-horizontal-subplots-containing-heatmaps-so-that-they-don

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!