# Possible to have nested (or hierarchical) legends?

**URL:** <https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376>\
**Category:** plotly.js\
**Created:** [October 11, 2016, 9:26pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376 "2016-10-11T21:26:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abalter](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@abalter](https://community.plotly.com/u/abalter)\
**Post date:** [October 11, 2016, 9:26pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/1 "2016-10-11T21:26:01Z")

</div>

This is what I would think “legend groups” are for, but by the examples, does not seem to do what I want. I would like to be able to have something like this for plots that say have 4 traces, with two in one category and two in another. The categories would be the same color.

Women  
—\*--- Age 10-30  
—±-- Age 30-60  
Men  
—o--- Age 10-30  
—#--- AGe 30-60

---

<div class="post-metadata">

**Author:** ![chelsea](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chelsea/32/196_2.png) [@chelsea](https://community.plotly.com/u/chelsea)\
**Post date:** [October 13, 2016, 9:17pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/2 "2016-10-13T21:17:44Z")

</div>

Hi there,  
Nested legends aren’t possible at the moment.  
Legend groups currently available in Plotly are for grouping traces so you can toggle groups of traces on/off at once ([https://plot.ly/python/reference/#scatter-legendgroup](https://plot.ly/python/reference/#scatter-legendgroup)).

---

<div class="post-metadata">

**Author:** ![abalter](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@abalter](https://community.plotly.com/u/abalter)\
**Post date:** [October 13, 2016, 10:57pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/3 "2016-10-13T22:57:43Z")

</div>

Thanks Chelsea! I was trying to understand the value of legend groups–at first glance seemed to be just another way to set line style. But the toggle thing is really nice.

---

<div class="post-metadata">

**Author:** ![archmoj](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/archmoj/32/8388_2.png) [@archmoj](https://community.plotly.com/u/archmoj)\
**Post date:** [January 22, 2020, 3:41pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/5 "2020-01-22T15:41:09Z")

</div>

@maxpuff it is under `Grouped Legend` here [https://plot.ly/python/legend/](https://plot.ly/python/legend/)

---

<div class="post-metadata">

**Author:** ![Butanium](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Butanium](https://community.plotly.com/u/Butanium)\
**Post date:** [July 19, 2023, 12:52pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/7 "2023-07-19T12:52:41Z")

</div>

Any news on this ?

---

<div class="post-metadata">

**Author:** ![jaredxfeng](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jaredxfeng](https://community.plotly.com/u/jaredxfeng)\
**Post date:** [March 12, 2024, 4:49pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/8 "2024-03-12T16:49:25Z")

</div>

Any news on this 2024? I am looking for assigning one subplot to multiple legend groups for multiple filtering.

---

<div class="post-metadata">

**Author:** ![Saratoga](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/saratoga/32/28634_2.png) [@Saratoga](https://community.plotly.com/u/Saratoga)\
**Post date:** [July 9, 2024, 3:10pm UTC](https://community.plotly.com/t/possible-to-have-nested-or-hierarchical-legends/2376/9 "2024-07-09T15:10:06Z")

</div>

Check the curveNumber value passed in the plotly\_legendclick event to know whether to hide the group or just the trace

https://codepen.io/saratoga01/embed/preview/KKLBJrj?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=KKLBJrj
