简体   繁体   中英

Python Plotly chart - generate different y-axis for each facet_row

I am trying to plot a chart using plotly (v 5.11.0) where I am trying to generate different y-axis for each facet_row. The y-axis should be matching for all facet_cols within that facet_row.

using fig.update_yaxes(matches = None) doesn't seem to solve the above problem. Please suggest any solution if possible.

fig = px.bar(query_fb, x = "modelName",
                             y = "value", facet_col = "holdingPeriod",
                             facet_col_wrap = 3,
                             facet_row = 'dataItem',
                             color = "modelName")
fig.for_each_yaxis(lambda y: y.update(title = ''))
fig.for_each_annotation(lambda a: a.update(
                    text=a.text.split("=")[-1]))
yxs = dict(tickformat = yaxisfmt )
fig.update_xaxes(visible=False)
fig.update_yaxes(yxs, tickformat = yaxisfmt,hoverformat = yaxisfmt)
fig.update_layout(autosize=False,
                  width= 250*len(self.modelId),
                  height=600,
                  margin=dict(l=50, r=10, b=60, t=60),
                  #legend= dict(orientation="h",),
                  title_x = 0.2,title= "")

Never mind, I figured the answer which worked for me. Thanks all!

for row_idx, row_figs in enumerate(fig._grid_ref): 
    for col_idx, col_fig in enumerate(row_figs):
          fig.update_yaxes(row=row_idx+1, col=col_idx+1,
                 matches = 'y'+str(len(row_figs)*row_idx+1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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