绘制轮廓子图,每个子图都有自己的颜色条 [英] Plotly contour subplots each having their own colorbar

查看:47
本文介绍了绘制轮廓子图,每个子图都有自己的颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Plotly生成轮廓.我使用子图在5x1网格中绘制了5个轮廓.我看不到一个选项,每个轮廓子图都有一个单独的颜色条.对于线图,我可以使用shared_xaxes或shared_yaxes选项,但无法找到文档,在此文档中我可以为该5x1网格中的每个子图都有一个单独的颜色条.

以下是我尝试通过的一些参考链接:

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/

解决方案

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:

这篇关于绘制轮廓子图,每个子图都有自己的颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆