简体   繁体   English

如何为包含图像的子图添加标题

[英]How to add titles to subplots containing images

Starting from a basic image example , I made 3 subplots:从一个基本的图像示例开始,我制作了 3 个子图:

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

imgs_rgb = (
    [[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
     [[0, 255, 0], [0, 0, 255], [255, 0, 0]]],
    [[[255, 127, 0], [127, 255, 0], [127, 0, 255]],
     [[127, 255, 0], [127, 0, 255], [255, 127, 0]]],
    [[[0, 255, 255], [0, 255, 127], [255, 0, 255]],
     [[255, 255, 0], [0, 255, 255], [127, 255, 0]]],
)    

fig = make_subplots(rows=len(imgs_rgb), cols=1)
for row, img_rgb in enumerate(imgs_rgb):
    fig.add_trace(
        go.Image(z=img_rgb),
        row=row+1,
        col=1
    )

fig.show()

How can we add a title/label to each individual subplot, as shown eg here: https://plotly.com/python/imshow/#exploring-3d-images-timeseries-and-sequences-of-images-with-facetcol我们如何为每个单独的子图添加标题/标签,如下所示: https ://plotly.com/python/imshow/#exploring-3d-images-timeseries-and-sequences-of-images-with-facetcol

显示 3 张具有不同标题的图像的图像

Note that I don't have plotly.express , so using its functionality isn't an option.请注意,我没有plotly.express ,因此不能选择使用它的功能。

You can just a pass the subplot titles when calling make_subplots() :您可以在调用make_subplots()时传递子图标题:

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

imgs_rgb = (
    [[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
     [[0, 255, 0], [0, 0, 255], [255, 0, 0]]],
    [[[255, 127, 0], [127, 255, 0], [127, 0, 255]],
     [[127, 255, 0], [127, 0, 255], [255, 127, 0]]],
    [[[0, 255, 255], [0, 255, 127], [255, 0, 255]],
     [[255, 255, 0], [0, 255, 255], [127, 255, 0]]],
)    

fig = make_subplots(rows=len(imgs_rgb), cols=1, subplot_titles=("Plot1", "Plot2", "Plot3"))
for row, img_rgb in enumerate(imgs_rgb):
    fig.add_trace(
        go.Image(z=img_rgb),
        row=row+1,
        col=1
    )

fig.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM