栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Plotly: how to make an unbounded vertical line in a subplot?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Plotly: how to make an unbounded vertical line in a subplot?

Is this your desired plot?

If that’s the case then you’ll have to inset a shape to each subplot defined
by the positions

row=i,col=j
. The following snippet will do that for you. If
you change the total numbers of subplots You’ll just need to have som
oversight of how your grid will look with regards to the numbers of rows and
columns.

from plotly.subplots import make_subplotsimport plotly.graph_objects as goimport numpy as npfig = make_subplots(    rows=2,    cols=2,    subplot_titles=list(map(str, range(4))),    shared_xaxes=True,    shared_yaxes=False,)time = np.linspace(-np.pi, np.pi, 1000)for i in range(4):    data = np.sin((i+1) * time)    fig.add_trace(        go.Scatter(y=data,x=time, name=str(i)),        row=1 if i in [0, 1] else 2,        col=1 if i in [0, 2] else 2,    )colors = ['blue', 'firebrick', 'green', 'purple']rows = 2cols = 2# add tracescounter=0 # for colorsfor i in range(1,3):    for j in range(1,3):        fig.add_shape(go.layout.Shape(type="line",       yref="paper",       xref="x",       x0=1,       y0=-2,       x1=1,       y1=2,       #line=dict(color="RoyalBlue", width=3),),       line=dict(color=colors[counter], width=3),),row=i,col=j)        counter = counter + 1fig.show()

Edit after comments:

To my knowledge, you can’t define an unbounded directly. But what you’re
trying to accomplish will work pretty good as long as you define axis limits
well beyond the data you want to visualize. Because contrary to your comment,
you can set the axis limits of each subplot like this:

# Set y ranges for each subplotfor i in range(1,3):    for j in range(1,3):        fig.update_yaxes(range=[-4, 4], row=i, col=j)

And instead of predefined limits you can find the proper max and min values
from your datasets.

Plot 2: Unzoomed

Plot 3: Zoomed out

I hope this is a bit more helpful!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382659.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号