@@ -156,14 +156,14 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
156
156
157
157
Returns
158
158
-------
159
- result : dict
159
+ trace_patch : dict
160
160
dict to be used to update trace
161
161
fit_results : dict
162
162
fit information to be used for trendlines
163
163
"""
164
164
if "line_close" in args and args ["line_close" ]:
165
165
trace_data = trace_data .append (trace_data .iloc [0 ])
166
- result = trace_spec .trace_patch .copy () or {}
166
+ trace_patch = trace_spec .trace_patch .copy () or {}
167
167
fit_results = None
168
168
hover_header = ""
169
169
custom_data_len = 0
@@ -186,12 +186,12 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
186
186
<= args ["dimensions_max_cardinality" ]
187
187
)
188
188
]
189
- result ["dimensions" ] = [
189
+ trace_patch ["dimensions" ] = [
190
190
dict (label = get_label (args , name ), values = column .values )
191
191
for (name , column ) in dims
192
192
]
193
193
if trace_spec .constructor == go .Splom :
194
- for d in result ["dimensions" ]:
194
+ for d in trace_patch ["dimensions" ]:
195
195
d ["axis" ] = dict (matches = True )
196
196
mapping_labels ["%{xaxis.title.text}" ] = "%{x}"
197
197
mapping_labels ["%{yaxis.title.text}" ] = "%{y}"
@@ -205,11 +205,11 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
205
205
)
206
206
):
207
207
if attr_name == "size" :
208
- if "marker" not in result :
209
- result ["marker" ] = dict ()
210
- result ["marker" ]["size" ] = trace_data [attr_value ]
211
- result ["marker" ]["sizemode" ] = "area"
212
- result ["marker" ]["sizeref" ] = sizeref
208
+ if "marker" not in trace_patch :
209
+ trace_patch ["marker" ] = dict ()
210
+ trace_patch ["marker" ]["size" ] = trace_data [attr_value ]
211
+ trace_patch ["marker" ]["sizemode" ] = "area"
212
+ trace_patch ["marker" ]["sizeref" ] = sizeref
213
213
mapping_labels [attr_label ] = "%{marker.size}"
214
214
elif attr_name == "marginal_x" :
215
215
if trace_spec .constructor == go .Histogram :
@@ -230,18 +230,18 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
230
230
sorted_trace_data = trace_data .sort_values (by = args ["x" ])
231
231
y = sorted_trace_data [args ["y" ]]
232
232
x = sorted_trace_data [args ["x" ]]
233
- result ["x" ] = x
233
+ trace_patch ["x" ] = x
234
234
235
235
if x .dtype .type == np .datetime64 :
236
236
x = x .astype (int ) / 10 ** 9 # convert to unix epoch seconds
237
237
238
238
if attr_value == "lowess" :
239
239
trendline = sm .nonparametric .lowess (y , x )
240
- result ["y" ] = trendline [:, 1 ]
240
+ trace_patch ["y" ] = trendline [:, 1 ]
241
241
hover_header = "<b>LOWESS trendline</b><br><br>"
242
242
elif attr_value == "ols" :
243
243
fit_results = sm .OLS (y .values , sm .add_constant (x .values )).fit ()
244
- result ["y" ] = fit_results .predict ()
244
+ trace_patch ["y" ] = fit_results .predict ()
245
245
hover_header = "<b>OLS trendline</b><br>"
246
246
hover_header += "%s = %g * %s + %g<br>" % (
247
247
args ["y" ],
@@ -258,19 +258,19 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
258
258
elif attr_name .startswith ("error" ):
259
259
error_xy = attr_name [:7 ]
260
260
arr = "arrayminus" if attr_name .endswith ("minus" ) else "array"
261
- if error_xy not in result :
262
- result [error_xy ] = {}
263
- result [error_xy ][arr ] = trace_data [attr_value ]
261
+ if error_xy not in trace_patch :
262
+ trace_patch [error_xy ] = {}
263
+ trace_patch [error_xy ][arr ] = trace_data [attr_value ]
264
264
elif attr_name == "custom_data" :
265
- result ["customdata" ] = trace_data [attr_value ].values
265
+ trace_patch ["customdata" ] = trace_data [attr_value ].values
266
266
custom_data_len = len (attr_value ) # number of custom data columns
267
267
elif attr_name == "hover_name" :
268
268
if trace_spec .constructor not in [
269
269
go .Histogram ,
270
270
go .Histogram2d ,
271
271
go .Histogram2dContour ,
272
272
]:
273
- result ["hovertext" ] = trace_data [attr_value ]
273
+ trace_patch ["hovertext" ] = trace_data [attr_value ]
274
274
if hover_header == "" :
275
275
hover_header = "<b>%{hovertext}</b><br><br>"
276
276
elif attr_name == "hover_data" :
@@ -285,70 +285,72 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
285
285
except (ValueError , AttributeError , KeyError ):
286
286
position = custom_data_len
287
287
custom_data_len += 1
288
- if "customdata" in result :
289
- result ["customdata" ] = np .hstack (
288
+ if "customdata" in trace_patch :
289
+ trace_patch ["customdata" ] = np .hstack (
290
290
(
291
- result ["customdata" ],
291
+ trace_patch ["customdata" ],
292
292
trace_data [col ].values [:, None ],
293
293
)
294
294
)
295
295
else :
296
- result ["customdata" ] = trace_data [col ].values [:, None ]
296
+ trace_patch ["customdata" ] = trace_data [col ].values [
297
+ :, None
298
+ ]
297
299
attr_label_col = get_decorated_label (args , col , None )
298
300
mapping_labels [attr_label_col ] = "%%{customdata[%d]}" % (
299
301
position
300
302
)
301
303
elif attr_name == "color" :
302
304
if trace_spec .constructor in [go .Choropleth , go .Choroplethmapbox ]:
303
- result ["z" ] = trace_data [attr_value ]
304
- result ["coloraxis" ] = "coloraxis1"
305
+ trace_patch ["z" ] = trace_data [attr_value ]
306
+ trace_patch ["coloraxis" ] = "coloraxis1"
305
307
mapping_labels [attr_label ] = "%{z}"
306
308
elif trace_spec .constructor in [
307
309
go .Sunburst ,
308
310
go .Treemap ,
309
311
go .Pie ,
310
312
go .Funnelarea ,
311
313
]:
312
- if "marker" not in result :
313
- result ["marker" ] = dict ()
314
+ if "marker" not in trace_patch :
315
+ trace_patch ["marker" ] = dict ()
314
316
315
317
if args .get ("color_is_continuous" ):
316
- result ["marker" ]["colors" ] = trace_data [attr_value ]
317
- result ["marker" ]["coloraxis" ] = "coloraxis1"
318
+ trace_patch ["marker" ]["colors" ] = trace_data [attr_value ]
319
+ trace_patch ["marker" ]["coloraxis" ] = "coloraxis1"
318
320
mapping_labels [attr_label ] = "%{color}"
319
321
else :
320
- result ["marker" ]["colors" ] = []
322
+ trace_patch ["marker" ]["colors" ] = []
321
323
mapping = {}
322
324
for cat in trace_data [attr_value ]:
323
325
if mapping .get (cat ) is None :
324
326
mapping [cat ] = args ["color_discrete_sequence" ][
325
327
len (mapping ) % len (args ["color_discrete_sequence" ])
326
328
]
327
- result ["marker" ]["colors" ].append (mapping [cat ])
329
+ trace_patch ["marker" ]["colors" ].append (mapping [cat ])
328
330
else :
329
331
colorable = "marker"
330
332
if trace_spec .constructor in [go .Parcats , go .Parcoords ]:
331
333
colorable = "line"
332
- if colorable not in result :
333
- result [colorable ] = dict ()
334
- result [colorable ]["color" ] = trace_data [attr_value ]
335
- result [colorable ]["coloraxis" ] = "coloraxis1"
334
+ if colorable not in trace_patch :
335
+ trace_patch [colorable ] = dict ()
336
+ trace_patch [colorable ]["color" ] = trace_data [attr_value ]
337
+ trace_patch [colorable ]["coloraxis" ] = "coloraxis1"
336
338
mapping_labels [attr_label ] = "%%{%s.color}" % colorable
337
339
elif attr_name == "animation_group" :
338
- result ["ids" ] = trace_data [attr_value ]
340
+ trace_patch ["ids" ] = trace_data [attr_value ]
339
341
elif attr_name == "locations" :
340
- result [attr_name ] = trace_data [attr_value ]
342
+ trace_patch [attr_name ] = trace_data [attr_value ]
341
343
mapping_labels [attr_label ] = "%{location}"
342
344
elif attr_name == "values" :
343
- result [attr_name ] = trace_data [attr_value ]
345
+ trace_patch [attr_name ] = trace_data [attr_value ]
344
346
_label = "value" if attr_label == "values" else attr_label
345
347
mapping_labels [_label ] = "%{value}"
346
348
elif attr_name == "parents" :
347
- result [attr_name ] = trace_data [attr_value ]
349
+ trace_patch [attr_name ] = trace_data [attr_value ]
348
350
_label = "parent" if attr_label == "parents" else attr_label
349
351
mapping_labels [_label ] = "%{parent}"
350
352
elif attr_name == "ids" :
351
- result [attr_name ] = trace_data [attr_value ]
353
+ trace_patch [attr_name ] = trace_data [attr_value ]
352
354
_label = "id" if attr_label == "ids" else attr_label
353
355
mapping_labels [_label ] = "%{id}"
354
356
elif attr_name == "names" :
@@ -358,22 +360,22 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
358
360
go .Pie ,
359
361
go .Funnelarea ,
360
362
]:
361
- result ["labels" ] = trace_data [attr_value ]
363
+ trace_patch ["labels" ] = trace_data [attr_value ]
362
364
_label = "label" if attr_label == "names" else attr_label
363
365
mapping_labels [_label ] = "%{label}"
364
366
else :
365
- result [attr_name ] = trace_data [attr_value ]
367
+ trace_patch [attr_name ] = trace_data [attr_value ]
366
368
else :
367
369
if attr_value :
368
- result [attr_name ] = trace_data [attr_value ]
370
+ trace_patch [attr_name ] = trace_data [attr_value ]
369
371
mapping_labels [attr_label ] = "%%{%s}" % attr_name
370
372
if trace_spec .constructor not in [
371
373
go .Parcoords ,
372
374
go .Parcats ,
373
375
]:
374
376
hover_lines = [k + "=" + v for k , v in mapping_labels .items ()]
375
- result ["hovertemplate" ] = hover_header + "<br>" .join (hover_lines )
376
- return result , fit_results
377
+ trace_patch ["hovertemplate" ] = hover_header + "<br>" .join (hover_lines )
378
+ return trace_patch , fit_results
377
379
378
380
379
381
def configure_axes (args , constructor , fig , orders ):
0 commit comments