Skip to content

Feature Request: BaseFigure.update enhancements for transfering express subplot layout  #3831

Closed
@pmiam

Description

@pmiam

Hello. I'm a recent plotly convert with particular appreciation for the express interface.

I think it's entirely possible to produce publication quality figures using only express and some layout adjustments. The necessary code is also succinct and easily readable, which is a welcome bonus when sharing notebooks with students/collaborators/the public for education/validation/the-plot-is-not-the-point purposes.

Therefore, I propose that the BaseFigure.update method be extended if possible, or an update_subplots method be implemented which improves a typical interactive workflow from this:

  import numpy as np

  matrix = np.random.random((50,50))
  sample = matrix[15,:]

  p0 = make_subplots(rows=1, cols=2)

  p1 = px.imshow(matrix)
  p1.update_xaxes(visible=False).update_yaxes(visible=False)

  p2 = px.line(sample)
  p2.update_layout(showlegend=False)

  for trace in p2.data:
      p0.add_trace(trace, row=1, col=1) 
  p0.add_trace(p1.data[0], row=1, col=2)

  #not ideal:
  import copy
  lo = copy.deepcopy(p0.layout)
  p0.update_layout(xaxis=p2.layout.xaxis, yaxis=p2.layout.yaxis, overwrite=False)
  p0.update_layout(xaxis2=p1.layout.xaxis, yaxis2=p1.layout.yaxis, coloraxis=p1.layout.coloraxis, overwrite=False)
  p0.layout.xaxis2.scaleanchor=None
  p0.update_layout(showlegend=False)
  p0.update_layout(lo, overwrite=False)

  p0.show(renderer='png')

44fa393099d29a479b38f88c641f353f0baf0968

to something like:

  #more ideal:
  p0.update_subplots(p2.layout, row=1, col=1)
  p0.update_subplots(p1.layout, row=1, col=2)
  p0.layout.xaxis2.scaleanchor=None

  p0.show(renderer='png')

I'm imagining the usual selector, row, col arguments as one possibility.

In this case, the selected xaxisN, yaxisN are updated with the corresponding figure's xaxis yaxis. Of course the axis_domain would probably have to be an exception. or perhaps the overwrite keyword could be used to control the merging of layouts. However, I feel the update method's overwrite switch has some unexpected behavior.

This is demonstrated in that I've used overwrite=false in every call above and yet I still have to copy the p0 layout in order to retain the p0 domains. I'm probably misunderstanding its purpose.

I also imagine the new figure will adopt top level layout properties from the constituents, probably with conflicting assignments simply resolved by order of calls. Finally, there are probably complications when the subfigure has subplots itself which I've not thought through.

I look forward to your input,
Panos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions