Skip to content

Commit 15f1f26

Browse files
committed
DOC: update docstring for PlotlyDict.update to reflect application of underscore magic for keyword arguments
1 parent e96bdb2 commit 15f1f26

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

plotly/graph_objs/graph_objs.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,23 @@ def help(self, attribute=None, return_help=False):
566566

567567
def update(self, dict1=None, **dict2):
568568
"""
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)
570571
571572
This recursively updates the structure of the original dictionary-like
572573
object with the new entries in the second and third objects. This
573574
allows users to update with large, nested structures.
574575
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+
575586
Note, because the dict2 packs up all the keyword arguments, you can
576587
specify the changes as a list of keyword agruments.
577588
@@ -589,6 +600,19 @@ def update(self, dict1=None, **dict2):
589600
obj
590601
{'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}
591602
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+
592616
This 'fully' supports duck-typing in that the call signature is
593617
identical, however this differs slightly from the normal update
594618
method provided by Python's dictionaries.

0 commit comments

Comments
 (0)