- 
 
- 
  Notifications
 You must be signed in to change notification settings 
- Fork 2.7k
 Allow shared_yaxes to work with secondary axes
 #5180
 
 New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
 
  Merged
 
 
 
 
 
 +149
 
 
 −111
 
 
 
 
 
 
 
 
  Merged
 Changes from all commits
 Commits
 
 
 Show all changes
 
 
 10 commits
 
 
 Select commit
 Hold shift + click to select a range
 
 fd64e00
 
 Fix sharing of secondary y-axis
 
 
 8f0ac47
 
 Add test
 
 
 948bc38
 
 black
 
 
 dcc607c
 
 black
 
 
 7fd2702
 
 Merge branch 'main' into secondary-y-shared
 
 
 gvwilson 99e7e3f
 
 feedback
 
 
 gmjw 42aea20
 
 linewidth
 
 
 gmjw a83c6b4
 
 ruff
 
 
 gmjw db0feea
 
 Merge branch 'main' into secondary-y-shared
 
 
 gmjw 610b7ee
 
 Merge branch 'main' into secondary-y-shared
 
 
 emilykl File filter
Filter by extension
Conversations
 Failed to load comments. 
 
 
 
  Loading
 
 Jump to
 
 Jump to file
 
 
 
 Failed to load files. 
 
 
 
  Loading
 
 Diff view
Diff view
There are no files selected for viewing
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -1828,115 +1828,127 @@ def test_secondary_y_traces(self): | |
| self.assertEqual(fig.to_plotly_json(), expected.to_plotly_json()) | ||
|  | ||
| def test_secondary_y_subplots(self): | ||
| fig = subplots.make_subplots( | ||
| rows=2, | ||
| cols=2, | ||
| specs=[ | ||
| [{"secondary_y": True}, {"secondary_y": True}], | ||
| [{"secondary_y": True}, {"secondary_y": True}], | ||
| ], | ||
| ) | ||
| for shared_y_axes in [False, True]: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally I would have passed in these options using  | ||
| fig = subplots.make_subplots( | ||
| rows=2, | ||
| cols=2, | ||
| shared_yaxes=shared_y_axes, | ||
| specs=[ | ||
| [{"secondary_y": True}, {"secondary_y": True}], | ||
| [{"secondary_y": True}, {"secondary_y": True}], | ||
| ], | ||
| ) | ||
|  | ||
| fig.add_scatter(y=[1, 3, 2], name="First", row=1, col=1) | ||
| fig.add_scatter(y=[2, 1, 3], name="Second", row=1, col=1, secondary_y=True) | ||
| fig.add_scatter(y=[1, 3, 2], name="First", row=1, col=1) | ||
| fig.add_scatter(y=[2, 1, 3], name="Second", row=1, col=1, secondary_y=True) | ||
|  | ||
| fig.add_scatter(y=[4, 3, 2], name="Third", row=1, col=2) | ||
| fig.add_scatter(y=[8, 1, 3], name="Forth", row=1, col=2, secondary_y=True) | ||
| fig.add_scatter(y=[4, 3, 2], name="Third", row=1, col=2) | ||
| fig.add_scatter(y=[8, 1, 3], name="Forth", row=1, col=2, secondary_y=True) | ||
|  | ||
| fig.add_scatter(y=[0, 2, 4], name="Fifth", row=2, col=1) | ||
| fig.add_scatter(y=[2, 1, 3], name="Sixth", row=2, col=1, secondary_y=True) | ||
| fig.add_scatter(y=[0, 2, 4], name="Fifth", row=2, col=1) | ||
| fig.add_scatter(y=[2, 1, 3], name="Sixth", row=2, col=1, secondary_y=True) | ||
|  | ||
| fig.add_scatter(y=[2, 4, 0], name="Fifth", row=2, col=2) | ||
| fig.add_scatter(y=[2, 3, 6], name="Sixth", row=2, col=2, secondary_y=True) | ||
| fig.add_scatter(y=[2, 4, 0], name="Fifth", row=2, col=2) | ||
| fig.add_scatter(y=[2, 3, 6], name="Sixth", row=2, col=2, secondary_y=True) | ||
|  | ||
| fig.update_traces(uid=None) | ||
| fig.update_traces(uid=None) | ||
|  | ||
| expected = Figure( | ||
| { | ||
| "data": [ | ||
| { | ||
| "name": "First", | ||
| "type": "scatter", | ||
| "xaxis": "x", | ||
| "y": [1, 3, 2], | ||
| "yaxis": "y", | ||
| }, | ||
| { | ||
| "name": "Second", | ||
| "type": "scatter", | ||
| "xaxis": "x", | ||
| "y": [2, 1, 3], | ||
| "yaxis": "y2", | ||
| }, | ||
| { | ||
| "name": "Third", | ||
| "type": "scatter", | ||
| "xaxis": "x2", | ||
| "y": [4, 3, 2], | ||
| "yaxis": "y3", | ||
| }, | ||
| { | ||
| "name": "Forth", | ||
| "type": "scatter", | ||
| "xaxis": "x2", | ||
| "y": [8, 1, 3], | ||
| "yaxis": "y4", | ||
| }, | ||
| { | ||
| "name": "Fifth", | ||
| "type": "scatter", | ||
| "xaxis": "x3", | ||
| "y": [0, 2, 4], | ||
| "yaxis": "y5", | ||
| }, | ||
| { | ||
| "name": "Sixth", | ||
| "type": "scatter", | ||
| "xaxis": "x3", | ||
| "y": [2, 1, 3], | ||
| "yaxis": "y6", | ||
| }, | ||
| { | ||
| "name": "Fifth", | ||
| "type": "scatter", | ||
| "xaxis": "x4", | ||
| "y": [2, 4, 0], | ||
| "yaxis": "y7", | ||
| }, | ||
| { | ||
| "name": "Sixth", | ||
| "type": "scatter", | ||
| "xaxis": "x4", | ||
| "y": [2, 3, 6], | ||
| "yaxis": "y8", | ||
| }, | ||
| ], | ||
| "layout": { | ||
| "xaxis": {"anchor": "y", "domain": [0.0, 0.37]}, | ||
| "xaxis2": { | ||
| "anchor": "y3", | ||
| "domain": [0.5700000000000001, 0.9400000000000001], | ||
| }, | ||
| "xaxis3": {"anchor": "y5", "domain": [0.0, 0.37]}, | ||
| "xaxis4": { | ||
| "anchor": "y7", | ||
| "domain": [0.5700000000000001, 0.9400000000000001], | ||
| expected = Figure( | ||
| { | ||
| "data": [ | ||
| { | ||
| "name": "First", | ||
| "type": "scatter", | ||
| "xaxis": "x", | ||
| "y": [1, 3, 2], | ||
| "yaxis": "y", | ||
| }, | ||
| { | ||
| "name": "Second", | ||
| "type": "scatter", | ||
| "xaxis": "x", | ||
| "y": [2, 1, 3], | ||
| "yaxis": "y2", | ||
| }, | ||
| { | ||
| "name": "Third", | ||
| "type": "scatter", | ||
| "xaxis": "x2", | ||
| "y": [4, 3, 2], | ||
| "yaxis": "y3", | ||
| }, | ||
| { | ||
| "name": "Forth", | ||
| "type": "scatter", | ||
| "xaxis": "x2", | ||
| "y": [8, 1, 3], | ||
| "yaxis": "y4", | ||
| }, | ||
| { | ||
| "name": "Fifth", | ||
| "type": "scatter", | ||
| "xaxis": "x3", | ||
| "y": [0, 2, 4], | ||
| "yaxis": "y5", | ||
| }, | ||
| { | ||
| "name": "Sixth", | ||
| "type": "scatter", | ||
| "xaxis": "x3", | ||
| "y": [2, 1, 3], | ||
| "yaxis": "y6", | ||
| }, | ||
| { | ||
| "name": "Fifth", | ||
| "type": "scatter", | ||
| "xaxis": "x4", | ||
| "y": [2, 4, 0], | ||
| "yaxis": "y7", | ||
| }, | ||
| { | ||
| "name": "Sixth", | ||
| "type": "scatter", | ||
| "xaxis": "x4", | ||
| "y": [2, 3, 6], | ||
| "yaxis": "y8", | ||
| }, | ||
| ], | ||
| "layout": { | ||
| "xaxis": {"anchor": "y", "domain": [0.0, 0.37]}, | ||
| "xaxis2": { | ||
| "anchor": "y3", | ||
| "domain": [0.5700000000000001, 0.9400000000000001], | ||
| }, | ||
| "xaxis3": {"anchor": "y5", "domain": [0.0, 0.37]}, | ||
| "xaxis4": { | ||
| "anchor": "y7", | ||
| "domain": [0.5700000000000001, 0.9400000000000001], | ||
| }, | ||
| "yaxis": {"anchor": "x", "domain": [0.575, 1.0]}, | ||
| "yaxis2": {"anchor": "x", "overlaying": "y", "side": "right"}, | ||
| "yaxis3": {"anchor": "x2", "domain": [0.575, 1.0]}, | ||
| "yaxis4": {"anchor": "x2", "overlaying": "y3", "side": "right"}, | ||
| "yaxis5": {"anchor": "x3", "domain": [0.0, 0.425]}, | ||
| "yaxis6": {"anchor": "x3", "overlaying": "y5", "side": "right"}, | ||
| "yaxis7": {"anchor": "x4", "domain": [0.0, 0.425]}, | ||
| "yaxis8": {"anchor": "x4", "overlaying": "y7", "side": "right"}, | ||
| }, | ||
| "yaxis": {"anchor": "x", "domain": [0.575, 1.0]}, | ||
| "yaxis2": {"anchor": "x", "overlaying": "y", "side": "right"}, | ||
| "yaxis3": {"anchor": "x2", "domain": [0.575, 1.0]}, | ||
| "yaxis4": {"anchor": "x2", "overlaying": "y3", "side": "right"}, | ||
| "yaxis5": {"anchor": "x3", "domain": [0.0, 0.425]}, | ||
| "yaxis6": {"anchor": "x3", "overlaying": "y5", "side": "right"}, | ||
| "yaxis7": {"anchor": "x4", "domain": [0.0, 0.425]}, | ||
| "yaxis8": {"anchor": "x4", "overlaying": "y7", "side": "right"}, | ||
| }, | ||
| } | ||
| ) | ||
| } | ||
| ) | ||
|  | ||
| expected.update_traces(uid=None) | ||
| if shared_y_axes: | ||
| expected["layout"]["yaxis2"]["matches"] = "y4" | ||
| expected["layout"]["yaxis2"]["showticklabels"] = False | ||
| expected["layout"]["yaxis3"]["matches"] = "y" | ||
| expected["layout"]["yaxis3"]["showticklabels"] = False | ||
| expected["layout"]["yaxis6"]["matches"] = "y8" | ||
| expected["layout"]["yaxis6"]["showticklabels"] = False | ||
| expected["layout"]["yaxis7"]["matches"] = "y5" | ||
| expected["layout"]["yaxis7"]["showticklabels"] = False | ||
|  | ||
| self.assertEqual(fig.to_plotly_json(), expected.to_plotly_json()) | ||
| expected.update_traces(uid=None) | ||
|  | ||
| self.assertEqual(fig.to_plotly_json(), expected.to_plotly_json()) | ||
|  | ||
| def test_if_passed_figure(self): | ||
| # assert it returns the same figure it was passed | ||
|  | ||
 Add this suggestion to a batch that can be applied as a single commit.
 This suggestion is invalid because no changes were made to the code.
 Suggestions cannot be applied while the pull request is closed.
 Suggestions cannot be applied while viewing a subset of changes.
 Only one suggestion per line can be applied in a batch.
 Add this suggestion to a batch that can be applied as a single commit.
 Applying suggestions on deleted lines is not supported.
 You must change the existing code in this line in order to create a valid suggestion.
 Outdated suggestions cannot be applied.
 This suggestion has been applied or marked resolved.
 Suggestions cannot be applied from pending reviews.
 Suggestions cannot be applied on multi-line comments.
 Suggestions cannot be applied while the pull request is queued to merge.
 Suggestion cannot be applied right now. Please check back later.