66 extension : .md
77 format_name : markdown
88 format_version : ' 1.3'
9- jupytext_version : 1.17.2
9+ jupytext_version : 1.19.1
1010 kernelspec :
1111 display_name : Python 3 (ipykernel)
1212 language : python
@@ -20,7 +20,7 @@ jupyter:
2020 name : python
2121 nbconvert_exporter : python
2222 pygments_lexer : ipython3
23- version : 3.9.0
23+ version : 3.14.3
2424 plotly :
2525 description : How to configure and style the legend in Plotly with Python.
2626 display_as : file_settings
@@ -832,6 +832,63 @@ fig.show()
832832
833833```
834834
835+ ### Legend Title Click Behavior
836+
837+ * New in 6.6*
838+
839+ When a figure has multiple legends:
840+
841+ - Single-clicking a legend title toggles the visibility of all items in that legend
842+ - Double-clicking a legend title toggles the visibility of all items in other legends
843+
844+ This default behavior can be changed for a legend by setting ` titleclick ` and ` titledoubleclick ` , which accept:
845+ - ` "toggle" ` : toggles the visibility of items in the clicked legend
846+ - ` "toggleothers" ` : toggles the visibility of items in other legends
847+ - ` False ` : disables click behavior
848+
849+ For example, to swap the behaviors:
850+
851+ ``` python
852+ import plotly.graph_objects as go
853+
854+ fig = go.Figure(
855+ data = [
856+ go.Scatter(x = [1 , 2 , 3 ], y = [1 , 2 , 3 ], name = " Trace 1" ),
857+ go.Scatter(x = [1 , 2 , 3 ], y = [2 , 3 , 4 ], name = " Trace 2" ),
858+ go.Scatter(x = [1 , 2 , 3 ], y = [3 , 4 , 5 ], name = " Trace 3" , legend = " legend2" ),
859+ go.Scatter(x = [1 , 2 , 3 ], y = [4 , 5 , 6 ], name = " Trace 4" , legend = " legend2" ),
860+ ],
861+ layout = dict (
862+ legend = dict (
863+ title = dict (text = " First Legend" ),
864+ titleclick = " toggleothers" ,
865+ titledoubleclick = " toggle" ,
866+ ),
867+ legend2 = dict (
868+ title = dict (text = " Second Legend" ),
869+ titleclick = " toggleothers" ,
870+ titledoubleclick = " toggle" ,
871+ y = 0.5 ,
872+ ),
873+ ),
874+ )
875+
876+ fig.show()
877+ ```
878+
879+ <!-- #region -->
880+ To disable title click behavior, set ` titleclick ` and ` titledoubleclick ` to ` False ` :
881+
882+ ``` python
883+ fig.update_layout(
884+ legend = dict (titleclick = False , titledoubleclick = False ),
885+ legend2 = dict (titleclick = False , titledoubleclick = False ),
886+ )
887+ ```
888+
889+ > ** Note:** Legend title click interactions are not supported for legends containing pie or pie-like traces.
890+ <!-- #endregion -->
891+
835892#### Reference
836893
837894See https://plotly.com/python/reference/layout/#layout-legend for more information!
0 commit comments