Plotly.py: Can't draw spike line across subplots with make_subplots in 4.0.0

Created on 23 Jul 2019  路  6Comments  路  Source: plotly/plotly.py

After upgrading to plotly 4.0.0, I can't see how to create a spike line across shared axes created with make_subplots.

Previously I was using code like this:

from plotly.tools import make_subplots
from plotly.io import write_html

fig = make_subplots(rows=4, cols=1, shared_xaxes=True)
x_vals = list(range(10))
y_vals = [x**2 for x in x_vals]
fig.add_scatter(x=x_vals, y=y_vals, row=1, col=1)
fig.add_scatter(x=x_vals, y=y_vals, row=2, col=1)
fig.add_scatter(x=x_vals, y=y_vals, row=3, col=1)
fig.add_scatter(x=x_vals, y=y_vals, row=4, col=1)

fig.update_xaxes(spikemode='across+marker')

write_html(fig, 'out.html', auto_open=True)

The resulting figure showed spike lines across axes because only one x axis was created:
image

But in 4.0, multiple x axes are created so the spike line no longer draws across all subplots:
image

Is there any way around this? Thanks!

Most helpful comment

I found it because now each axis made by make_subplots is an individual object even shared_xaxes=True.

This is mentioned in https://plot.ly/python/v4-migration/.

So it is actually "across" the plot are for the axis object

but I want enhancement in order to draw it like version3xx did..

All 6 comments

I found it because now each axis made by make_subplots is an individual object even shared_xaxes=True.

This is mentioned in https://plot.ly/python/v4-migration/.

So it is actually "across" the plot are for the axis object

but I want enhancement in order to draw it like version3xx did..

As a simple workaround, you can just do fig.update_traces(xaxis="x1") which rebinds all your traces to the x-axis you want the spikelines to join up with.

Thanks it works!
Just needed to set it to the xaxis which is at the bottom.
Then the ticklabels remain visible.
fig.update_traces(xaxis="x4")

Thanks it works!
Just needed to set it to the xaxis which is at the bottom.
Then the ticklabels remain visible.
fig.update_traces(xaxis="x4")

Note that this would only work on single column subplots. Can spikes be syncronized in two separate axis?

Hi all,

The fig.update_traces(xaxis="whichever") workaround tends to mess with the ability to zoom vertically when clicking on the y axis, it only allows horizontal zooming:

spikemode

Is there any other possibility to have a single X axis for all subplots, when share X is active?

Thanks,
Guille

I can confirm that the workaround of naming axes identically doesn't work when one or more subplots are using a distinct axis. In my application I have two columns where the first column contains a single subplot, and the second column has 6 subplots with a shared x-axis. But none of these shared axes act as a common axis.

I wanted to mention that the plotly documentation gives another workaround here: https://plotly.com/python/subplots/#subplots-with-shared-axes-lowlevel-api

Basicly, you will create a scatter plot for each "subplot", then you will manually define the axis names and domains of each "subplot", using the domains to arrange the "subplots" (they aren't technically subplots because you aren't using any plotly function with subplot in its name) as you desire.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmilienDupont picture EmilienDupont  路  4Comments

ghtmtt picture ghtmtt  路  5Comments

vlizanae picture vlizanae  路  4Comments

jonmmease picture jonmmease  路  3Comments

aplowman picture aplowman  路  3Comments