MCPcopy Index your code
hub / github.com/plotly/plotly.py / apply_default_cascade

Function apply_default_cascade

plotly/express/_core.py:1007–1100  ·  view source on GitHub ↗
(args, constructor)

Source from the content-addressed store, hash-verified

1005
1006
1007def apply_default_cascade(args, constructor):
1008 # first we apply px.defaults to unspecified args
1009
1010 for param in defaults.__slots__:
1011 if param in args and args[param] is None:
1012 args[param] = getattr(defaults, param)
1013
1014 # load the default template if set, otherwise "plotly"
1015 if args["template"] is None:
1016 if pio.templates.default is not None:
1017 args["template"] = pio.templates.default
1018 else:
1019 args["template"] = "plotly"
1020
1021 try:
1022 # retrieve the actual template if we were given a name
1023 args["template"] = pio.templates[args["template"]]
1024 except Exception:
1025 # otherwise try to build a real template
1026 args["template"] = go.layout.Template(args["template"])
1027
1028 # if colors not set explicitly or in px.defaults, defer to a template
1029 # if the template doesn't have one, we set some final fallback defaults
1030 if "color_continuous_scale" in args:
1031 if (
1032 args["color_continuous_scale"] is None
1033 and args["template"].layout.colorscale.sequential
1034 ):
1035 args["color_continuous_scale"] = [
1036 x[1] for x in args["template"].layout.colorscale.sequential
1037 ]
1038 if args["color_continuous_scale"] is None:
1039 args["color_continuous_scale"] = sequential.Viridis
1040
1041 # if color_discrete_sequence not set explicitly or in px.defaults,
1042 # see if we can defer to template. Try trace-specific colors first,
1043 # then layout.colorway, then set reasonable defaults
1044 if "color_discrete_sequence" in args:
1045 if args["color_discrete_sequence"] is None and constructor is not None:
1046 if constructor == "timeline":
1047 trace_type = "bar"
1048 else:
1049 trace_type = constructor().type
1050 if trace_data_list := getattr(args["template"].data, trace_type, None):
1051 trace_specific_colors = [
1052 trace_data.marker.color
1053 for trace_data in trace_data_list
1054 if hasattr(trace_data, "marker")
1055 and hasattr(trace_data.marker, "color")
1056 ]
1057 # If template contains at least one color for this trace type, assign to color_discrete_sequence
1058 if any(trace_specific_colors):
1059 args["color_discrete_sequence"] = trace_specific_colors
1060 # fallback to layout.colorway if trace-specific colors not available
1061 if args["color_discrete_sequence"] is None and args["template"].layout.colorway:
1062 args["color_discrete_sequence"] = args["template"].layout.colorway
1063 # final fallback to default qualitative palette
1064 if args["color_discrete_sequence"] is None:

Callers 5

_swatchesFunction · 0.90
_swatches_continuousFunction · 0.90
_swatches_cyclicalFunction · 0.90
make_figureFunction · 0.85
imshowFunction · 0.85

Calls 1

constructorFunction · 0.85

Tested by

no test coverage detected