File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
packages/python/plotly/plotly
tests/test_core/test_update_objects Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -859,6 +859,29 @@ def update_traces(
859
859
trace .update (patch , ** kwargs )
860
860
return self
861
861
862
+ def update_layout (self , dict1 = None , ** kwargs ):
863
+ """
864
+ Update the properties of the figure's layout with a dict and/or with
865
+ keyword arguments.
866
+
867
+ This recursively updates the structure of the original
868
+ layout with the values in the input dict / keyword arguments.
869
+
870
+ Parameters
871
+ ----------
872
+ dict1 : dict
873
+ Dictionary of properties to be updated
874
+ kwargs :
875
+ Keyword/value pair of properties to be updated
876
+
877
+ Returns
878
+ -------
879
+ BaseFigure
880
+ The Figure object that the update_layout method was called on
881
+ """
882
+ self .layout .update (dict1 , ** kwargs )
883
+ return self
884
+
862
885
def _select_layout_subplots_by_prefix (
863
886
self ,
864
887
prefix ,
Original file line number Diff line number Diff line change
1
+ from unittest import TestCase
2
+ import plotly .graph_objects as go
3
+
4
+
5
+ class TestUpdateLayout (TestCase ):
6
+
7
+ def test_update_layout_kwargs (self ):
8
+ # Create initial figure
9
+ fig = go .Figure ()
10
+ fig .layout .title .font .size = 10
11
+
12
+ # Grab copy of original figure
13
+ orig_fig = go .Figure (fig )
14
+
15
+ fig .update_layout (title_font_family = 'Courier New' )
16
+ orig_fig .layout .update (title_font_family = 'Courier New' )
17
+ self .assertEqual (fig , orig_fig )
18
+
19
+ def test_update_layout_dict (self ):
20
+ # Create initial figure
21
+ fig = go .Figure ()
22
+ fig .layout .title .font .size = 10
23
+
24
+ # Grab copy of original figure
25
+ orig_fig = go .Figure (fig )
26
+
27
+ fig .update_layout (dict (title = dict (font = dict (family = 'Courier New' ))))
28
+ orig_fig .layout .update (title_font_family = 'Courier New' )
29
+ self .assertEqual (fig , orig_fig )
You can’t perform that action at this time.
0 commit comments