Feature Request: Horizontal movement of `tracegroupgap` when `orientation='h'`
Thanks for your interest in Plotly.py!
Before opening an issue, please search for existing and closed issues :)
Please accompany bug reports with a reproducible example. Please use the latest version of plotly.py in your report unless not applicable.
Note that GitHub Issues are meant to be used for bug reports and feature requests only. Implementation or usage questions should be asked on community.plotly.com or on Stack Overflow (tagged plotly).
Request:
Dear plotly gang,
We all love plotly, it is blazingly fast and swiftly.
Recently, I followed a thread on the community guidelines regarding "Subplots with individual legends" on it. This thread covered having the grouped legends divided for each horizontal subplot by using the tracegroupgap argument in the legend attribute of update_layout method.
However, if one would want to use the same methodology but now set orientation='h' for the legend, this fails since the tracegroupgap attribute only moves it vertically and not horizontally. Ergo, my request would be to also update this method to take into account that if orientation='h' then tracegroupgap should move horizontally and vice versa.
Example code
Some dummy code on how it could look like:
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
def main():
df = px.data.gapminder().query("continent=='Americas'")
fig = make_subplots(rows=1, cols=3)
fig.append_trace(go.Scatter(
x=df.query("country == 'Canada'")['year'],
y=df.query("country == 'Canada'")['lifeExp'],
name = 'Canada',
legendgroup = '1'
), row=1, col=1)
fig.append_trace(go.Scatter(
x=df.query("country == 'United States'")['year'],
y=df.query("country == 'United States'")['lifeExp'],
name = 'United States',
legendgroup = '1'
), row=1, col=1)
fig.append_trace(go.Scatter(
x=df.query("country == 'Mexico'")['year'],
y=df.query("country == 'Mexico'")['lifeExp'],
name = 'Mexico',
legendgroup = '2'
), row=1, col=2)
fig.append_trace(go.Scatter(
x=df.query("country == 'Colombia'")['year'],
y=df.query("country == 'Colombia'")['lifeExp'],
name = 'Colombia',
legendgroup = '2'
), row=1, col=2)
fig.append_trace(go.Scatter(
x=df.query("country == 'Brazil'")['year'],
y=df.query("country == 'Brazil'")['lifeExp'],
name = 'Brazil',
legendgroup = '2'
), row=1, col=2)
fig.append_trace(go.Scatter(
x=df.query("country == 'Argentina'")['year'],
y=df.query("country == 'Argentina'")['lifeExp'],
name = 'Argentina',
legendgroup = '3'
), row=1, col=3)
fig.append_trace(go.Scatter(
x=df.query("country == 'Chile'")['year'],
y=df.query("country == 'Chile'")['lifeExp'],
name = 'Chile',
legendgroup = '3'
), row=1, col=3)
fig.update_layout(
legend=dict(
traceorder='normal',
orientation='h',
xanchor='center',
yanchor='bottom',
y=1.02,
x=0.5,
tracegroupgap=500, # doesn't impact the final plot anything since orientation='h', but would be nice!
)
)
if __name__ == '__main__':
main()