When using plotly subplots, here's a typical example (from https://plotly.com/python/subplots/):
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=3, cols=1)
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=[100, 110, 120]), row=2, col=1)
fig.append_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1)
fig.update_layout(height=600, width=600, title_text="Stacked Subplots")
fig.show()
This doesn't look too bad with just 3 data series, but when I have e.g. 5 subplots that each have a few series, it gets quite difficult to visually associate an item in the legend with where it appears in a plot.
Is it possible to move the legend items downward to align them with the plots in which they appear?
Incidentally, I'm actually working in R, not Python, and I'm generating a list of the individual plots using ggplot and ggplotly(), then assembling them like so:
p <- subplot(plots, shareX=TRUE, nrows=length(plots))
layout_args <- c(list(p,
title=title,
xaxis=list(title = 'Time (Local)'),
legend=list(orientation = 'v')),
yaxis_args)
p <- do.call(layout, layout_args)
htmlwidgets::saveWidget(htmlwidgets::as_widget(p), outfile)
But I'm guessing a solution will probably apply equally to both R and Python.


