使用固定的轴范围,并将它们应用于所有的子图,以确保它们缩放相等。可以通过设置layout
参数中子图的xaxis
和yaxis
对象的range
属性来实现此目的。以下是示例代码:
import plotly.graph_objs as go
# Create first subplot
trace1 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6])
subplot1 = go.Subplot(data=[trace1])
# Create second subplot
trace2 = go.Scatter(x=[10, 20, 30], y=[40, 50, 60])
subplot2 = go.Subplot(data=[trace2])
# Set fixed axis ranges
x_axis_range = [0, 35]
y_axis_range = [0, 65]
# Apply axis ranges to both subplots
subplot1["layout"]["xaxis"].update(range=x_axis_range)
subplot1["layout"]["yaxis"].update(range=y_axis_range)
subplot2["layout"]["xaxis"].update(range=x_axis_range)
subplot2["layout"]["yaxis"].update(range=y_axis_range)
# Create figure with subplots
fig = go.Figure(data=[subplot1, subplot2])
# Show figure
fig.show()