Is there a way to change the layout not for the whole figure, but only a single (or several) subplot(s) in a figure (plotly 5.22)? Example code:
import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots
x = np.random.rand(2000)
y1 = np.random.rand(2000)
y2 = np.random.randn(2000)
fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=x, y=y1, mode='markers'), row=1, col=1)
fig.add_trace(go.Scatter(x=x, y=y2, mode='markers'), row=1, col=2)
# I want this to affect only the first subplot
fig.update_layout(plot_bgcolor='#ff0000')
fig.show()
I know there are methods to apply a function for each xxx like fig.for_each_trace()
or fig.for_each_xaxis()
, but there’s no fig.for_each_subplot()
.
I have no idea how to address any subplot in the figure particularly except for functions that take the row
and col
parameters, like fig.add_trace()
.