简体   繁体   中英

Plotly subplot produces two graphs with same data, although traces contain different data

When plotting 2 heatmaps, it gives me both heatmaps, each with different settings, but with the data of the first one.

from plotly import tools
import plotly.graph_objs as go
import numpy as np
from plotly.offline import plot

Data:

a = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
b = np.array([[2, 3, 4],[4, 5, 6],[5, 6, 7]])


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


trace1 = go.Heatmapgl(
        z=a,
        showscale=False,
        colorscale='Viridis',
        name='aa'
     )


trace2 = go.Heatmapgl(
        z=b,
        showscale=False,
        name='bb'
    )


fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)


plot(fig, filename='simple-subplot')

This gives me 2 heatmaps, but the second one also contains z values of 1, 2 or 3.

Anyone knows what the issue is here?

If you use newer versions of plotly (I'm on 4.2.0 ) you can easily get what you want by replacing a few lines from you original code and apply go.Hetmap .

Plot:

在此处输入图片说明

Code:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

a = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
b = np.array([[2, 3, 4],[4, 5, 6],[5, 6, 7]])

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


trace1 = go.Heatmap(
        z=a,
        showscale=False,
        colorscale='Viridis',
        name='aa'
     )


trace2 = go.Heatmap(
        z=b,
        showscale=False,
        name='bb'
    )

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)

fig.show()

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