@@ -137,7 +137,7 @@ def make_mapping(args, variable):
137
137
)
138
138
139
139
140
- def make_trace_kwargs (args , trace_spec , g , mapping_labels , sizeref ):
140
+ def make_trace_kwargs (args , trace_spec , trace_data , mapping_labels , sizeref ):
141
141
"""Populates a dict with arguments to update trace
142
142
143
143
Parameters
@@ -147,7 +147,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
147
147
trace_spec : NamedTuple
148
148
which kind of trace to be used (has constructor, marginal etc.
149
149
attributes)
150
- g : pandas DataFrame
150
+ trace_data : pandas DataFrame
151
151
data
152
152
mapping_labels : dict
153
153
to be used for hovertemplate
@@ -162,7 +162,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
162
162
fit information to be used for trendlines
163
163
"""
164
164
if "line_close" in args and args ["line_close" ]:
165
- g = g .append (g .iloc [0 ])
165
+ trace_data = trace_data .append (trace_data .iloc [0 ])
166
166
result = trace_spec .trace_patch .copy () or {}
167
167
fit_results = None
168
168
hover_header = ""
@@ -173,7 +173,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
173
173
if k == "dimensions" :
174
174
dims = [
175
175
(name , column )
176
- for (name , column ) in g .iteritems ()
176
+ for (name , column ) in trace_data .iteritems ()
177
177
if ((not v ) or (name in v ))
178
178
and (
179
179
trace_spec .constructor != go .Parcoords
@@ -207,7 +207,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
207
207
if k == "size" :
208
208
if "marker" not in result :
209
209
result ["marker" ] = dict ()
210
- result ["marker" ]["size" ] = g [v ]
210
+ result ["marker" ]["size" ] = trace_data [v ]
211
211
result ["marker" ]["sizemode" ] = "area"
212
212
result ["marker" ]["sizeref" ] = sizeref
213
213
mapping_labels [v_label ] = "%{marker.size}"
@@ -218,13 +218,18 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
218
218
if trace_spec .constructor == go .Histogram :
219
219
mapping_labels ["count" ] = "%{x}"
220
220
elif k == "trendline" :
221
- if v in ["ols" , "lowess" ] and args ["x" ] and args ["y" ] and len (g ) > 1 :
221
+ if (
222
+ v in ["ols" , "lowess" ]
223
+ and args ["x" ]
224
+ and args ["y" ]
225
+ and len (trace_data ) > 1
226
+ ):
222
227
import statsmodels .api as sm
223
228
224
229
# sorting is bad but trace_specs with "trendline" have no other attrs
225
- g2 = g .sort_values (by = args ["x" ])
226
- y = g2 [args ["y" ]]
227
- x = g2 [args ["x" ]]
230
+ sorted_trace_data = trace_data .sort_values (by = args ["x" ])
231
+ y = sorted_trace_data [args ["y" ]]
232
+ x = sorted_trace_data [args ["x" ]]
228
233
result ["x" ] = x
229
234
230
235
if x .dtype .type == np .datetime64 :
@@ -255,17 +260,17 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
255
260
arr = "arrayminus" if k .endswith ("minus" ) else "array"
256
261
if error_xy not in result :
257
262
result [error_xy ] = {}
258
- result [error_xy ][arr ] = g [v ]
263
+ result [error_xy ][arr ] = trace_data [v ]
259
264
elif k == "custom_data" :
260
- result ["customdata" ] = g [v ].values
265
+ result ["customdata" ] = trace_data [v ].values
261
266
custom_data_len = len (v ) # number of custom data columns
262
267
elif k == "hover_name" :
263
268
if trace_spec .constructor not in [
264
269
go .Histogram ,
265
270
go .Histogram2d ,
266
271
go .Histogram2dContour ,
267
272
]:
268
- result ["hovertext" ] = g [v ]
273
+ result ["hovertext" ] = trace_data [v ]
269
274
if hover_header == "" :
270
275
hover_header = "<b>%{hovertext}</b><br><br>"
271
276
elif k == "hover_data" :
@@ -282,15 +287,18 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
282
287
custom_data_len += 1
283
288
if "customdata" in result :
284
289
result ["customdata" ] = np .hstack (
285
- (result ["customdata" ], g [col ].values [:, None ])
290
+ (
291
+ result ["customdata" ],
292
+ trace_data [col ].values [:, None ],
293
+ )
286
294
)
287
295
else :
288
- result ["customdata" ] = g [col ].values [:, None ]
296
+ result ["customdata" ] = trace_data [col ].values [:, None ]
289
297
v_label_col = get_decorated_label (args , col , None )
290
298
mapping_labels [v_label_col ] = "%%{customdata[%d]}" % (position )
291
299
elif k == "color" :
292
300
if trace_spec .constructor in [go .Choropleth , go .Choroplethmapbox ]:
293
- result ["z" ] = g [v ]
301
+ result ["z" ] = trace_data [v ]
294
302
result ["coloraxis" ] = "coloraxis1"
295
303
mapping_labels [v_label ] = "%{z}"
296
304
elif trace_spec .constructor in [
@@ -303,13 +311,13 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
303
311
result ["marker" ] = dict ()
304
312
305
313
if args .get ("color_is_continuous" ):
306
- result ["marker" ]["colors" ] = g [v ]
314
+ result ["marker" ]["colors" ] = trace_data [v ]
307
315
result ["marker" ]["coloraxis" ] = "coloraxis1"
308
316
mapping_labels [v_label ] = "%{color}"
309
317
else :
310
318
result ["marker" ]["colors" ] = []
311
319
mapping = {}
312
- for cat in g [v ]:
320
+ for cat in trace_data [v ]:
313
321
if mapping .get (cat ) is None :
314
322
mapping [cat ] = args ["color_discrete_sequence" ][
315
323
len (mapping ) % len (args ["color_discrete_sequence" ])
@@ -321,24 +329,24 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
321
329
colorable = "line"
322
330
if colorable not in result :
323
331
result [colorable ] = dict ()
324
- result [colorable ]["color" ] = g [v ]
332
+ result [colorable ]["color" ] = trace_data [v ]
325
333
result [colorable ]["coloraxis" ] = "coloraxis1"
326
334
mapping_labels [v_label ] = "%%{%s.color}" % colorable
327
335
elif k == "animation_group" :
328
- result ["ids" ] = g [v ]
336
+ result ["ids" ] = trace_data [v ]
329
337
elif k == "locations" :
330
- result [k ] = g [v ]
338
+ result [k ] = trace_data [v ]
331
339
mapping_labels [v_label ] = "%{location}"
332
340
elif k == "values" :
333
- result [k ] = g [v ]
341
+ result [k ] = trace_data [v ]
334
342
_label = "value" if v_label == "values" else v_label
335
343
mapping_labels [_label ] = "%{value}"
336
344
elif k == "parents" :
337
- result [k ] = g [v ]
345
+ result [k ] = trace_data [v ]
338
346
_label = "parent" if v_label == "parents" else v_label
339
347
mapping_labels [_label ] = "%{parent}"
340
348
elif k == "ids" :
341
- result [k ] = g [v ]
349
+ result [k ] = trace_data [v ]
342
350
_label = "id" if v_label == "ids" else v_label
343
351
mapping_labels [_label ] = "%{id}"
344
352
elif k == "names" :
@@ -348,14 +356,14 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
348
356
go .Pie ,
349
357
go .Funnelarea ,
350
358
]:
351
- result ["labels" ] = g [v ]
359
+ result ["labels" ] = trace_data [v ]
352
360
_label = "label" if v_label == "names" else v_label
353
361
mapping_labels [_label ] = "%{label}"
354
362
else :
355
- result [k ] = g [v ]
363
+ result [k ] = trace_data [v ]
356
364
else :
357
365
if v :
358
- result [k ] = g [v ]
366
+ result [k ] = trace_data [v ]
359
367
mapping_labels [v_label ] = "%%{%s}" % k
360
368
if trace_spec .constructor not in [
361
369
go .Parcoords ,
0 commit comments