@@ -137,7 +137,7 @@ def make_mapping(args, variable):
137137 )
138138
139139
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 ):
141141 """Populates a dict with arguments to update trace
142142
143143 Parameters
@@ -147,7 +147,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
147147 trace_spec : NamedTuple
148148 which kind of trace to be used (has constructor, marginal etc.
149149 attributes)
150- g : pandas DataFrame
150+ trace_data : pandas DataFrame
151151 data
152152 mapping_labels : dict
153153 to be used for hovertemplate
@@ -162,7 +162,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
162162 fit information to be used for trendlines
163163 """
164164 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 ])
166166 result = trace_spec .trace_patch .copy () or {}
167167 fit_results = None
168168 hover_header = ""
@@ -173,7 +173,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
173173 if k == "dimensions" :
174174 dims = [
175175 (name , column )
176- for (name , column ) in g .iteritems ()
176+ for (name , column ) in trace_data .iteritems ()
177177 if ((not v ) or (name in v ))
178178 and (
179179 trace_spec .constructor != go .Parcoords
@@ -207,7 +207,7 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
207207 if k == "size" :
208208 if "marker" not in result :
209209 result ["marker" ] = dict ()
210- result ["marker" ]["size" ] = g [v ]
210+ result ["marker" ]["size" ] = trace_data [v ]
211211 result ["marker" ]["sizemode" ] = "area"
212212 result ["marker" ]["sizeref" ] = sizeref
213213 mapping_labels [v_label ] = "%{marker.size}"
@@ -218,13 +218,18 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
218218 if trace_spec .constructor == go .Histogram :
219219 mapping_labels ["count" ] = "%{x}"
220220 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+ ):
222227 import statsmodels .api as sm
223228
224229 # 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" ]]
228233 result ["x" ] = x
229234
230235 if x .dtype .type == np .datetime64 :
@@ -255,17 +260,17 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
255260 arr = "arrayminus" if k .endswith ("minus" ) else "array"
256261 if error_xy not in result :
257262 result [error_xy ] = {}
258- result [error_xy ][arr ] = g [v ]
263+ result [error_xy ][arr ] = trace_data [v ]
259264 elif k == "custom_data" :
260- result ["customdata" ] = g [v ].values
265+ result ["customdata" ] = trace_data [v ].values
261266 custom_data_len = len (v ) # number of custom data columns
262267 elif k == "hover_name" :
263268 if trace_spec .constructor not in [
264269 go .Histogram ,
265270 go .Histogram2d ,
266271 go .Histogram2dContour ,
267272 ]:
268- result ["hovertext" ] = g [v ]
273+ result ["hovertext" ] = trace_data [v ]
269274 if hover_header == "" :
270275 hover_header = "<b>%{hovertext}</b><br><br>"
271276 elif k == "hover_data" :
@@ -282,15 +287,18 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
282287 custom_data_len += 1
283288 if "customdata" in result :
284289 result ["customdata" ] = np .hstack (
285- (result ["customdata" ], g [col ].values [:, None ])
290+ (
291+ result ["customdata" ],
292+ trace_data [col ].values [:, None ],
293+ )
286294 )
287295 else :
288- result ["customdata" ] = g [col ].values [:, None ]
296+ result ["customdata" ] = trace_data [col ].values [:, None ]
289297 v_label_col = get_decorated_label (args , col , None )
290298 mapping_labels [v_label_col ] = "%%{customdata[%d]}" % (position )
291299 elif k == "color" :
292300 if trace_spec .constructor in [go .Choropleth , go .Choroplethmapbox ]:
293- result ["z" ] = g [v ]
301+ result ["z" ] = trace_data [v ]
294302 result ["coloraxis" ] = "coloraxis1"
295303 mapping_labels [v_label ] = "%{z}"
296304 elif trace_spec .constructor in [
@@ -303,13 +311,13 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
303311 result ["marker" ] = dict ()
304312
305313 if args .get ("color_is_continuous" ):
306- result ["marker" ]["colors" ] = g [v ]
314+ result ["marker" ]["colors" ] = trace_data [v ]
307315 result ["marker" ]["coloraxis" ] = "coloraxis1"
308316 mapping_labels [v_label ] = "%{color}"
309317 else :
310318 result ["marker" ]["colors" ] = []
311319 mapping = {}
312- for cat in g [v ]:
320+ for cat in trace_data [v ]:
313321 if mapping .get (cat ) is None :
314322 mapping [cat ] = args ["color_discrete_sequence" ][
315323 len (mapping ) % len (args ["color_discrete_sequence" ])
@@ -321,24 +329,24 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
321329 colorable = "line"
322330 if colorable not in result :
323331 result [colorable ] = dict ()
324- result [colorable ]["color" ] = g [v ]
332+ result [colorable ]["color" ] = trace_data [v ]
325333 result [colorable ]["coloraxis" ] = "coloraxis1"
326334 mapping_labels [v_label ] = "%%{%s.color}" % colorable
327335 elif k == "animation_group" :
328- result ["ids" ] = g [v ]
336+ result ["ids" ] = trace_data [v ]
329337 elif k == "locations" :
330- result [k ] = g [v ]
338+ result [k ] = trace_data [v ]
331339 mapping_labels [v_label ] = "%{location}"
332340 elif k == "values" :
333- result [k ] = g [v ]
341+ result [k ] = trace_data [v ]
334342 _label = "value" if v_label == "values" else v_label
335343 mapping_labels [_label ] = "%{value}"
336344 elif k == "parents" :
337- result [k ] = g [v ]
345+ result [k ] = trace_data [v ]
338346 _label = "parent" if v_label == "parents" else v_label
339347 mapping_labels [_label ] = "%{parent}"
340348 elif k == "ids" :
341- result [k ] = g [v ]
349+ result [k ] = trace_data [v ]
342350 _label = "id" if v_label == "ids" else v_label
343351 mapping_labels [_label ] = "%{id}"
344352 elif k == "names" :
@@ -348,14 +356,14 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref):
348356 go .Pie ,
349357 go .Funnelarea ,
350358 ]:
351- result ["labels" ] = g [v ]
359+ result ["labels" ] = trace_data [v ]
352360 _label = "label" if v_label == "names" else v_label
353361 mapping_labels [_label ] = "%{label}"
354362 else :
355- result [k ] = g [v ]
363+ result [k ] = trace_data [v ]
356364 else :
357365 if v :
358- result [k ] = g [v ]
366+ result [k ] = trace_data [v ]
359367 mapping_labels [v_label ] = "%%{%s}" % k
360368 if trace_spec .constructor not in [
361369 go .Parcoords ,
0 commit comments