Skip to content

Axis match bug#5581

Open
richmanpoorman wants to merge 2 commits intoplotly:mainfrom
richmanpoorman:axis-match-bug
Open

Axis match bug#5581
richmanpoorman wants to merge 2 commits intoplotly:mainfrom
richmanpoorman:axis-match-bug

Conversation

@richmanpoorman
Copy link
Copy Markdown

Link to issue

Closes #5427

Description of change

  • Bug was that function marked the axis to be connected, but the trace_kwargs still had unique axes
  • Change: change the keyword argument for the trace, so that when the graph is initialized, it uses the correct axis instead of the autogenerated one
  • Note: The program generates a unique axis label for each subgraph, and then overwrites the label (under this fix)

Demo

image

Testing strategy

Used this test code to see if the line showed up; since this is a visibility test, no unit tests were provided

`# Create sample data
df = pd.DataFrame({
'x': pd.date_range('2024-01-01', periods=100),
'y1': range(100),
'y2': [x**2 for x in range(100)]
})

Create subplots

fig = make_subplots(
rows=2, cols=1,
shared_xaxes=True,
vertical_spacing=0.02
)

fig.add_trace(go.Scatter(x=df['x'], y=df['y1'], name='Line 1'), row=1, col=1)
fig.add_trace(go.Scatter(x=df['x'], y=df['y2'], name='Line 2'), row=2, col=1)

fig.update_traces(xaxis='x2')

fig.update_xaxes(
showspikes=True,
spikemode='across',
spikesnap='cursor',
spikecolor='black',
spikethickness=1
)

fig.update_layout(hovermode='x unified')
fig.show()`

Additional information (optional)

This is my first pull request, so please let me know if there is anything

Guidelines

- Bug was that function marked the axis to be connected, but the trace_kwargs still had unique axes
- Change: change the keyword argument for the trace, so that when the graph is initialized, it uses the correct axis instead of the autogenerated one
- Note: The program generates a unique axis label for each subgraph, and then overwrites the label (under this fix)
@richmanpoorman
Copy link
Copy Markdown
Author

I just wanted to say that the label used to sync all of the axes together is last generated one, ie instead of using "x", it will use "x2" as the label for both of axes. This is because it is the last graph (the bottom one) that has the labeling on the axis. Looking at the code that was already there, this seems to be the intended outcome, but it doesn't seem intuitive to me.

If it isn't intended, it may need to change more (including how the graph is initialized and the order which things are processed), but I didn't want to make too big of a change.

Let me know if this is right or wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: make_subplots() doesn't use shared x-axes for traces on different subplots, even when shared_xaxes is set to True

1 participant