Dana_Miles
Dana_Miles

Reputation: 429

Plotly - change order of subplots

I would like to change the order of the subplots, e.g. by sorting by the mean, starting with the lowest. Currently: Blue, Red, Green. Desired: Red, Green, Blue

Any ideas? Thanks!

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=3, cols=1, subplot_titles=('Blue', 'Red', 'Green'))
fig.append_trace(go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
), row=1, col=1)

fig.append_trace(go.Scatter(
    x=[2, 3, 4],
    y=[10, 11, 12]
), row=2, col=1)

fig.append_trace(go.Scatter(
    x=[0, 1, 2],
    y=[100, 110, 120],
), row=3, col=1)


fig.update_layout(height=600, width=600, title_text="Stacked Subplots")
fig.show()

Upvotes: 1

Views: 1496

Answers (1)

s3dev
s3dev

Reputation: 9681

To change the order of the subplots, simply:

  • Update the subplot_titles parameter to order the titles
  • Update the row= parameter of each plot to position the graph accordingly

Here's a link to that section of the Plotly docs. Albeit, says basically the same thing as the subplot docs you've reviewed.

Upvotes: 3

Related Questions