plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Allow `shared_yaxes` to work with secondary axes

Open gmjw opened this issue 8 months ago • 3 comments

  • [x] I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • [x] I have added tests (if submitting a new feature or correcting a bug) or modified existing tests.
  • [ ] For a new feature, I have added documentation examples in an existing or new tutorial notebook (please see the doc checklist as well).
  • [ ] I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • [ ] For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

The shared_yaxes parameter to make_subplots did not previously work on secondary y-axes. It had no effect.

This PR fixes this, without affecting how the parameter is applied to normal plots (without secondary y-axes). I have added a simple test to show how the new code "matches" secondary y-axes. The sharing for secondary y-axes is applied right-to-left, in the same way that the sharing for primary y-axes is applied left-to-right (I believe this results in the clearest separation of tick marks when viewing the final plot).

I believe this is a bugfix/improvement. I'm not sure if it's a new feature worthy of any documentation.

I will add some images showing a before/after comparison in comments.

gmjw avatar May 12 '25 21:05 gmjw

This is the output of the test adjusted in the PR, with shared_yaxes=True, before and after the changes. You can see that after the changes the secondary y-axes are shared across rows, whereas previously only primary y-axes were shared.

fig_test_before fig_test_after

gmjw avatar May 12 '25 22:05 gmjw

This is my first PR to this repo, I've done my best but please let me know if there's anything I've forgotten or that could be done better.

In particular I'm not sure if/how I should add to the CHANGELOG file.

gmjw avatar May 12 '25 22:05 gmjw

thanks @gmjw - I'll try to get this merged in for the 6.2 release.

gvwilson avatar May 20 '25 14:05 gvwilson

Thanks @gvwilson - just checking in to see if this could be merged soon - thanks!

gmjw avatar Jun 25 '25 21:06 gmjw

Hi @gvwilson - just to say that I hope this is ready to merge now, if you have time to review. Thanks!

gmjw avatar Jul 31 '25 22:07 gmjw

cc @emilykl one more review and merge?

gvwilson avatar Aug 01 '25 12:08 gvwilson

Hi @emilykl - no rush but just wanted to bump this PR for another look if you have time, many thanks!

gmjw avatar Aug 27 '25 18:08 gmjw