Skip to content

Commit 95f78c2

Browse files
result -> trace_patch
1 parent 94303bc commit 95f78c2

File tree

1 file changed

+45
-43
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+45
-43
lines changed

packages/python/plotly/plotly/express/_core.py

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
156156
157157
Returns
158158
-------
159-
result : dict
159+
trace_patch : dict
160160
dict to be used to update trace
161161
fit_results : dict
162162
fit information to be used for trendlines
163163
"""
164164
if "line_close" in args and args["line_close"]:
165165
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 {}
167167
fit_results = None
168168
hover_header = ""
169169
custom_data_len = 0
@@ -186,12 +186,12 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
186186
<= args["dimensions_max_cardinality"]
187187
)
188188
]
189-
result["dimensions"] = [
189+
trace_patch["dimensions"] = [
190190
dict(label=get_label(args, name), values=column.values)
191191
for (name, column) in dims
192192
]
193193
if trace_spec.constructor == go.Splom:
194-
for d in result["dimensions"]:
194+
for d in trace_patch["dimensions"]:
195195
d["axis"] = dict(matches=True)
196196
mapping_labels["%{xaxis.title.text}"] = "%{x}"
197197
mapping_labels["%{yaxis.title.text}"] = "%{y}"
@@ -205,11 +205,11 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
205205
)
206206
):
207207
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
213213
mapping_labels[attr_label] = "%{marker.size}"
214214
elif attr_name == "marginal_x":
215215
if trace_spec.constructor == go.Histogram:
@@ -230,18 +230,18 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
230230
sorted_trace_data = trace_data.sort_values(by=args["x"])
231231
y = sorted_trace_data[args["y"]]
232232
x = sorted_trace_data[args["x"]]
233-
result["x"] = x
233+
trace_patch["x"] = x
234234

235235
if x.dtype.type == np.datetime64:
236236
x = x.astype(int) / 10 ** 9 # convert to unix epoch seconds
237237

238238
if attr_value == "lowess":
239239
trendline = sm.nonparametric.lowess(y, x)
240-
result["y"] = trendline[:, 1]
240+
trace_patch["y"] = trendline[:, 1]
241241
hover_header = "<b>LOWESS trendline</b><br><br>"
242242
elif attr_value == "ols":
243243
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()
245245
hover_header = "<b>OLS trendline</b><br>"
246246
hover_header += "%s = %g * %s + %g<br>" % (
247247
args["y"],
@@ -258,19 +258,19 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
258258
elif attr_name.startswith("error"):
259259
error_xy = attr_name[:7]
260260
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]
264264
elif attr_name == "custom_data":
265-
result["customdata"] = trace_data[attr_value].values
265+
trace_patch["customdata"] = trace_data[attr_value].values
266266
custom_data_len = len(attr_value) # number of custom data columns
267267
elif attr_name == "hover_name":
268268
if trace_spec.constructor not in [
269269
go.Histogram,
270270
go.Histogram2d,
271271
go.Histogram2dContour,
272272
]:
273-
result["hovertext"] = trace_data[attr_value]
273+
trace_patch["hovertext"] = trace_data[attr_value]
274274
if hover_header == "":
275275
hover_header = "<b>%{hovertext}</b><br><br>"
276276
elif attr_name == "hover_data":
@@ -285,70 +285,72 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
285285
except (ValueError, AttributeError, KeyError):
286286
position = custom_data_len
287287
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(
290290
(
291-
result["customdata"],
291+
trace_patch["customdata"],
292292
trace_data[col].values[:, None],
293293
)
294294
)
295295
else:
296-
result["customdata"] = trace_data[col].values[:, None]
296+
trace_patch["customdata"] = trace_data[col].values[
297+
:, None
298+
]
297299
attr_label_col = get_decorated_label(args, col, None)
298300
mapping_labels[attr_label_col] = "%%{customdata[%d]}" % (
299301
position
300302
)
301303
elif attr_name == "color":
302304
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"
305307
mapping_labels[attr_label] = "%{z}"
306308
elif trace_spec.constructor in [
307309
go.Sunburst,
308310
go.Treemap,
309311
go.Pie,
310312
go.Funnelarea,
311313
]:
312-
if "marker" not in result:
313-
result["marker"] = dict()
314+
if "marker" not in trace_patch:
315+
trace_patch["marker"] = dict()
314316

315317
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"
318320
mapping_labels[attr_label] = "%{color}"
319321
else:
320-
result["marker"]["colors"] = []
322+
trace_patch["marker"]["colors"] = []
321323
mapping = {}
322324
for cat in trace_data[attr_value]:
323325
if mapping.get(cat) is None:
324326
mapping[cat] = args["color_discrete_sequence"][
325327
len(mapping) % len(args["color_discrete_sequence"])
326328
]
327-
result["marker"]["colors"].append(mapping[cat])
329+
trace_patch["marker"]["colors"].append(mapping[cat])
328330
else:
329331
colorable = "marker"
330332
if trace_spec.constructor in [go.Parcats, go.Parcoords]:
331333
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"
336338
mapping_labels[attr_label] = "%%{%s.color}" % colorable
337339
elif attr_name == "animation_group":
338-
result["ids"] = trace_data[attr_value]
340+
trace_patch["ids"] = trace_data[attr_value]
339341
elif attr_name == "locations":
340-
result[attr_name] = trace_data[attr_value]
342+
trace_patch[attr_name] = trace_data[attr_value]
341343
mapping_labels[attr_label] = "%{location}"
342344
elif attr_name == "values":
343-
result[attr_name] = trace_data[attr_value]
345+
trace_patch[attr_name] = trace_data[attr_value]
344346
_label = "value" if attr_label == "values" else attr_label
345347
mapping_labels[_label] = "%{value}"
346348
elif attr_name == "parents":
347-
result[attr_name] = trace_data[attr_value]
349+
trace_patch[attr_name] = trace_data[attr_value]
348350
_label = "parent" if attr_label == "parents" else attr_label
349351
mapping_labels[_label] = "%{parent}"
350352
elif attr_name == "ids":
351-
result[attr_name] = trace_data[attr_value]
353+
trace_patch[attr_name] = trace_data[attr_value]
352354
_label = "id" if attr_label == "ids" else attr_label
353355
mapping_labels[_label] = "%{id}"
354356
elif attr_name == "names":
@@ -358,22 +360,22 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
358360
go.Pie,
359361
go.Funnelarea,
360362
]:
361-
result["labels"] = trace_data[attr_value]
363+
trace_patch["labels"] = trace_data[attr_value]
362364
_label = "label" if attr_label == "names" else attr_label
363365
mapping_labels[_label] = "%{label}"
364366
else:
365-
result[attr_name] = trace_data[attr_value]
367+
trace_patch[attr_name] = trace_data[attr_value]
366368
else:
367369
if attr_value:
368-
result[attr_name] = trace_data[attr_value]
370+
trace_patch[attr_name] = trace_data[attr_value]
369371
mapping_labels[attr_label] = "%%{%s}" % attr_name
370372
if trace_spec.constructor not in [
371373
go.Parcoords,
372374
go.Parcats,
373375
]:
374376
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
377379

378380

379381
def configure_axes(args, constructor, fig, orders):

0 commit comments

Comments
 (0)