@@ -566,12 +566,23 @@ def help(self, attribute=None, return_help=False):
566
566
567
567
def update (self , dict1 = None , ** dict2 ):
568
568
"""
569
- Update current dict with dict1 and then dict2.
569
+ Update current dict with dict1 and then dict2. Returns a modifed
570
+ version of self (updates are applied in place)
570
571
571
572
This recursively updates the structure of the original dictionary-like
572
573
object with the new entries in the second and third objects. This
573
574
allows users to update with large, nested structures.
574
575
576
+ For all items in dict2, the "underscore magic" syntax for setting deep
577
+ attributes applies. To use this syntax, specify the path to the
578
+ attribute, separating each part of the path by an underscore. For
579
+ example, to set the "marker.line.color" attribute you can do
580
+ `obj.update(marker_line_color="red")` instead of
581
+ `obj.update(marker={"line": {"color": "red"}})`. Note that you can
582
+ use this in conjuction with the `plotly.graph_objs.attr` function to
583
+ set groups of deep attributes. See docstring for `attr` and the
584
+ examples below for more information.
585
+
575
586
Note, because the dict2 packs up all the keyword arguments, you can
576
587
specify the changes as a list of keyword agruments.
577
588
@@ -589,6 +600,19 @@ def update(self, dict1=None, **dict2):
589
600
obj
590
601
{'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}
591
602
603
+ # Update with underscore magic syntax for xaxis.domain
604
+ obj = Layout(title='my title', xaxis=XAxis(range=[0,1], domain=[0,1]))
605
+ obj.update(title="new title", xaxis_domain=[0, 0.8])
606
+ obj
607
+ {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}
608
+
609
+ # Use underscore magic and attr function for xaxis
610
+ obj = Layout().update(
611
+ title="new title",
612
+ xaxis=attr(range=[0, 1], domain=[0, 0.8]))
613
+ obj
614
+ {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}
615
+
592
616
This 'fully' supports duck-typing in that the call signature is
593
617
identical, however this differs slightly from the normal update
594
618
method provided by Python's dictionaries.
0 commit comments