我试图在python中创建一个绘图,它允许我将2x轴添加到一个绘图中。我刚刚试过了,但是每个教程和文档都用y和x数据在绘图中添加第二条跟踪,但是如果这样做,它将生成第二行,我只想要一条表示两轴的行。我的意思是,主要是x轴是底部的,第二轴可以是上的。图将使用y和x数据生成(主要是x轴)。
我已经有了,但你可以看到不是很清楚.

fig = go.Figure()
for percentile, color in zip(percentiles_m, colors_m):
fig.add_trace(
go.Scatter(
y=curves_df[percentile],
x=[curves_df.index, remaining_patients],
name=percentile + "th",
mode="lines+markers",
textposition="top center",
line=dict(color=color),
)
)
fig.update_xaxes(title_text="Remaining patients/Repetition", tickangle=0, tickfont=dict(size=11), dividerwidth=1)
fig.update_yaxes(title_text=feature_selected, tickfont=dict(size=11))发布于 2022-11-09 10:54:26
根据我的经验,您可以使用x=[tuple(main_x),tuple(sub_x)]设置主xaxis和子xaxis。请参阅以下代码:
fig_1 = go.Figure(data=[
go.Bar(x=[tuple(df['Season']),
tuple(df['category_name'])],
y=list(df['sale_dollars'])),
])其结果是:

https://stackoverflow.com/questions/74372689
复制相似问题