Reputation: 233
I created 7 subplots using plotly.subplot.make_subplots()
.
Each plot is obtained with fig.add_trace(go.Scatter())
.
Usually to change ticks along one axis you could use
fig.update_layout(
xaxis=dict(
tickmode='array',
tickvals= [...] #some intervals,
ticktext= [...] #some text to show along the axes
)
)
But in this case, since fig
is the whole figure created by make_subplots()
, this solution is wrong.
How can I refer only to one subplot at a time?
Is there any parameter I can set in go.Scatter()
that does this?
I looked up the documentation but so far I haven't found what I'm looking for.
Upvotes: 1
Views: 5034
Reputation: 35240
First, the best way to understand the graph structure is to view fig.data, where each subplot has its attributes set in dictionary form. For the axes, the subplots are numbered sequentially as y, y2, y3. If you want to set this in any range, set it in the list.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
df = px.data.iris()
fig = make_subplots(rows=1, cols=3)
for i,s in enumerate(df.species.unique()):
dfs = df.query('species == @s')
fig.add_trace(go.Scatter(
mode='markers',
x=dfs['sepal_width'],
y=dfs['sepal_length'],
name=s),
row=1, col=i+1
)
fig.update_layout(yaxis=dict(tickvals=[5.1, 5.9, 6.3, 7.5]),
yaxis2=dict(tickvals=[5.0, 6.0, 7.0, 8.5]),
yaxis3=dict(tickvals=[5.0, 6.0, 6.5, 7.0]),
)
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()
Upvotes: 4