简体   繁体   中英

Plotly - change order of subplots

I would like to change the order of the subplots, eg 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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM