如何在两个Plotly Heatmap子图中共享相同的Z轴

4
我希望为两个热图子图设置相同的Z轴。 目前,plotly会生成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')

你找到解决方案了吗? - Rylan Schaeffer
1个回答

2
我最终只需在循环之前计算出刻度的最大值,然后将其应用于两个图表。这样,两个刻度就会重叠在一起,但你不会注意到它们。
#Define the max value of you scale before looping:
maxValue = ...

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接