Skip to content

Commit 78a4434

Browse files
committed
Fix for #1050. Can't create numbered subplots in update
1 parent 213602d commit 78a4434

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Diff for: plotly/basedatatypes.py

+12
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,18 @@ def _perform_update(plotly_obj, update_obj):
21002100
return
21012101
elif isinstance(plotly_obj, BasePlotlyType):
21022102

2103+
# Handle initializing subplot ids
2104+
# -------------------------------
2105+
# This should be valid even if xaxis2 hasn't been initialized:
2106+
# >>> layout.update(xaxis2={'title': 'xaxis 2'})
2107+
if isinstance(plotly_obj, BaseLayoutType):
2108+
for key in update_obj:
2109+
if key not in plotly_obj:
2110+
match = fullmatch(plotly_obj._subplotid_prop_re, key)
2111+
if match:
2112+
# We need to create a subplotid object
2113+
plotly_obj[key] = {}
2114+
21032115
# Handle invalid properties
21042116
# -------------------------
21052117
invalid_props = [

Diff for: plotly/tests/test_core/test_graph_objs/test_layout_subplots.py

+28
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,31 @@ def test_subplot_props_in_constructor(self):
153153
self.assertEqual(layout.geo4.bgcolor, 'blue')
154154
self.assertEqual(layout.ternary5.sum, 120)
155155
self.assertEqual(layout.scene6.dragmode, 'zoom')
156+
157+
def test_create_subplot_with_update(self):
158+
159+
self.layout.update(xaxis2=go.layout.XAxis(title='xaxis 2'),
160+
yaxis3=go.layout.YAxis(title='yaxis 3'),
161+
geo4=go.layout.Geo(bgcolor='blue'),
162+
ternary5=go.layout.Ternary(sum=120),
163+
scene6=go.layout.Scene(dragmode='zoom'))
164+
165+
self.assertEqual(self.layout.xaxis2.title, 'xaxis 2')
166+
self.assertEqual(self.layout.yaxis3.title, 'yaxis 3')
167+
self.assertEqual(self.layout.geo4.bgcolor, 'blue')
168+
self.assertEqual(self.layout.ternary5.sum, 120)
169+
self.assertEqual(self.layout.scene6.dragmode, 'zoom')
170+
171+
def test_create_subplot_with_update_dict(self):
172+
173+
self.layout.update({'xaxis2': {'title': 'xaxis 2'},
174+
'yaxis3': {'title': 'yaxis 3'},
175+
'geo4': {'bgcolor': 'blue'},
176+
'ternary5': {'sum': 120},
177+
'scene6': {'dragmode': 'zoom'}})
178+
179+
self.assertEqual(self.layout.xaxis2.title, 'xaxis 2')
180+
self.assertEqual(self.layout.yaxis3.title, 'yaxis 3')
181+
self.assertEqual(self.layout.geo4.bgcolor, 'blue')
182+
self.assertEqual(self.layout.ternary5.sum, 120)
183+
self.assertEqual(self.layout.scene6.dragmode, 'zoom')

0 commit comments

Comments
 (0)