Plotly contour subplots each having their own colorbar

隐身守侯 提交于 2021-02-16 15:21:31

问题


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 colorbar for each contour subplot. For line plots I can use shared_xaxes or shared_yaxes options, but unable to find documentation where I can have a separate colorbar for each subplot in this 5x1 grid.

Here are some reference links I tried to go through:

https://plot.ly/python/contour-plots/

https://plot.ly/python/heatmaps-contours-and-2dhistograms-tutorial/

https://plot.ly/python/reference/


回答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:




回答2:


It is not possible to have different colorbars for each contour sublplot. Found this out from Plotly community:

https://community.plot.ly/t/using-custom-colorscale-with-subplots/524/2



来源:https://stackoverflow.com/questions/44376974/plotly-contour-subplots-each-having-their-own-colorbar

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