如何在2个绘图热图子图上共享相同的Z轴

时间:2018-02-16 13:05:07

标签: python plotly heatmap

我想为2个热图子图设置相同的Z轴。 目前,情节生成2个独立的规模并叠加它们。

Superimposed scaled

这是我目前所处的位置,但无法合并两个尺度...

import plotly.offline as py
import plotly.graph_objs as go
from plotly import tools

fig = tools.make_subplots(rows=1, cols=2, shared_yaxes=True)
# shared_zaxes=True does not exists
data = [
        {'x' : [1, 2, 3],
         'y' : [1, 2, 3],
         'z' : [[2,5,6],[8,7,3],[1,7,3]]
         },
        {'x' : [1, 2, 3],
         'y' : [1, 2, 3],
         'z' : [[1,2,3],[2,3,1],[1,2,3]]
        }
        ]
maxValue = 0

for i in [0,1]:
    print(i)
    trace = go.Heatmap(z=data[i]['z'],
                       x=data[i]['x'],
                       y=data[i]['y'],
                       colorscale='Jet')
    fig.append_trace(dict(trace, showscale=True), 1, i+1) 

    maxValue = max(max(data[i]['z'])) if max(max(data[i]['z'])) > maxValue else maxValue

fig['layout'].update(title='Same Zaxis')
fig['layout']['scene']['zaxis'].update(range=[0,maxValue])

py.plot(fig , filename='sameZaxis-heatmap')

1 个答案:

答案 0 :(得分:0)

我最终简单地在循环之前计算比例尺的最大值,然后将其应用于两个图形。然后,两个音阶都叠加了,但是您看不到。

#Define the max value of you scale before looping:
maxValue = ...

for i in [0,1]:
    trace = go.Heatmap(...
                       zmin=0,
                       zmax=maxValue))