Skip to content Skip to sidebar Skip to footer

Plotly Contour Subplots Each Having Their Own Colorbar

I am trying to generate contours using Plotly. There are 5 contours which I am plotting in a 5x1 grid using subplots. I am unable to see an option by which I can have a separate co

Solution 1:

Each subplot does in fact have its own colorbar. The issue is that by default they are plotted on top of each other so it's hard to tell there are several of them. By setting the len and y parameters of the colorbar, you can space them out and see how they are associated with each contour. Here's an example, loosely based on the Plotly contour docs:

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

fig = plotly.tools.make_subplots(rows=3, cols=1)
cbarlocs = [.85, .5, .15]
zmax = [2, 5, 10]

for n in range(3):
    trace = go.Contour(
            z=[[10, 10.625, 12.5, 15.625, 20],
               [5.625, 6.25, 8.125, 11.25, 15.625],
               [2.5, 3.125, 5., 8.125, 12.5],
               [0.625, 1.25, 3.125, 6.25, 10.625],
               [0, 0.625, 2.5, 5.625, 10]], 
            colorbar=dict(len=0.25, y=cbarlocs[n]), 
            zmin=0, zmax=zmax[n])

    fig.append_trace(trace, n+1, 1)

plotly.offline.iplot(fig)

The crucial part is colorbar=dict(len=0.25, y=cbarlocs[n]). This code results in something that looks like this:

enter image description here


Post a Comment for "Plotly Contour Subplots Each Having Their Own Colorbar"