Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
Gareth Williams committed May 12, 2025
commit 8f0ac4726aff7733c943ca7830a9ba4bac4cab1a
212 changes: 112 additions & 100 deletions 212 tests/test_core/test_subplots/test_make_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would have passed in these options using mark.parametrize, but I don't think that is possible with unittest TestCase methods.

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
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.