子图的绘图范围不变

问题描述 投票:0回答:0

我正在尝试使用

xaxis_range
设置子图的范围,但我发现它仅适用于左侧子图

数据

data = {'variable': {0: 'Case', 1: 'Exam', 2: 'History', 3: 'MAP', 4: 'Volume'},
 'margins_fluid': {0: 0.497, 1: 0.668, 2: 0.506, 3: 0.489, 4: 0.718},
 'margins_vp': {0: 0.809, 1: 0.893, 2: 0.832, 3: 0.904, 4: 0.92}}

df = pd.DataFrame(data)

情节

# create subplots
fig = make_subplots(
    rows=1,
    cols=2,
    shared_xaxes=False,
    shared_yaxes=True,
    horizontal_spacing=0,
    subplot_titles=['<b>Fluid</b>', '<b>Vasopressor</b>'])

fig.append_trace(
    go.Bar(
        x=df['margins_fluid'],
        y=df['variable'], 
        text=df["margins_fluid"], 
        textposition='inside',
        texttemplate="%{x:.4p}",
        orientation='h', 
        width=0.7, # space between bars 
        showlegend=False, ), 
        1, 1) # 1,1 represents row 1 column 1 in the plot grid

fig.append_trace(
    go.Bar(
        x=df['margins_vp'],
        y=df['variable'], 
        text=df["margins_vp"],
        textposition='inside',
        texttemplate="%{x:.4p}",
        orientation='h', 
        width=0.7, 
        showlegend=False), 
        1, 2) # 1,2 represents row 1 column 2 in the plot grid

fig.update_xaxes(
    tickformat=',.0%', 
    row=1,
    col=1,
    autorange='reversed',)
fig.update_xaxes(
    tickformat=',.0%', 
    row=1,
    col=2)

fig.update_layout(
    title_text="Title",
    barmode="group",
    width=800, 
    height=700,
    title_x=0.5,
    xaxis_range=[0, 1], # This doesn't work
    xaxis2_range=[0, 1], # This works
)

fig.show()

python pandas plotly
© www.soinside.com 2019 - 2024. All rights reserved.