Hey there everyone.
From an example taken here: Shared X-axis with Sub and Side-by-Side Plots and Click Events in HTML Output File
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
N = 100
x = np.linspace(0, 1, N)
fig = make_subplots(2, 2)
for i in range(1, 3):
for j in range(1, 3):
fig.append_trace(go.Scatter(x=x, y=np.random.random(N)), i, j)
fig.update_xaxes(matches='x')
fig.show()
This is the result:
In my case I want to create a plot with 2 rows and 1 column where the x axis have the same behaviour as the script above. But Iām using dates and int values which is not working.
This is the actual code Iām trying to get to work.
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
N = 100
x = [0, 1, 2, 3, 5]
y = ["2022-01-01", "2022-02-01", "2022-03-01", "2022-04-01", "2022-05-01"]
fig = make_subplots(
2,
1,
row_heights=[0.98, 0.02],
vertical_spacing=0.1,
)
for i in range(1, 3):
for j in range(1, 2):
if i == 1:
fig.append_trace(go.Scatter(x=x, y=np.random.random(N)), i, j)
if i == 2:
fig.append_trace(go.Scatter(x=y, y=[0, 0, 0, 0, 0]), i, j)
fig.update_xaxes(matches="x")
fig.show()
If you need this to be clarified or more information, just ask me for .
Thanks in advance.