From e7863c6262c7d0d2e07c2c3393fdb9e5d12ccb2e Mon Sep 17 00:00:00 2001 From: Ismail Uddin Date: Fri, 22 Mar 2019 02:47:12 -0700 Subject: [PATCH 1/4] Added support for opacity kwarg to scatter, scatter_3d, scatter_matrix and scatter_polar --- plotly_express/_chart_types.py | 5 +++++ plotly_express/_core.py | 7 +++++-- plotly_express/_doc.py | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plotly_express/_chart_types.py b/plotly_express/_chart_types.py index fa6ce5c..a9b69d7 100644 --- a/plotly_express/_chart_types.py +++ b/plotly_express/_chart_types.py @@ -18,6 +18,7 @@ def scatter( x=None, y=None, color=None, + opacity=None, symbol=None, size=None, hover_name=None, @@ -325,6 +326,7 @@ def scatter_3d( y=None, z=None, color=None, + opacity=None, symbol=None, size=None, text=None, @@ -416,6 +418,7 @@ def scatter_ternary( b=None, c=None, color=None, + opacity=None, symbol=None, size=None, text=None, @@ -483,6 +486,7 @@ def scatter_polar( r=None, theta=None, color=None, + opacity=None, symbol=None, size=None, hover_name=None, @@ -774,6 +778,7 @@ def scatter_matrix( data_frame, dimensions=None, color=None, + opacity=None, symbol=None, size=None, category_orders={}, diff --git a/plotly_express/_core.py b/plotly_express/_core.py index a549c57..ebf84b0 100644 --- a/plotly_express/_core.py +++ b/plotly_express/_core.py @@ -133,6 +133,8 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range) or len(args["data_frame"][name].unique()) <= 20 ) ] + elif k == 'opacity': + pass elif v or (trace_spec.constructor == go.Histogram and k in ["x", "y"]): if k == "size": if "marker" not in result: @@ -141,7 +143,6 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range) result["marker"]["sizemode"] = "area" result["marker"]["sizeref"] = sizeref mapping_labels.append(("%s=%%{%s}" % (v_label, "marker.size"), None)) - elif k == "trendline": if v in ["ols", "lowess"] and args["x"] and args["y"] and len(g) > 1: import statsmodels.api as sm @@ -568,7 +569,7 @@ def one_group(x): def infer_config(args, constructor, trace_patch): attrables = ( - ["x", "y", "z", "a", "b", "c", "r", "theta", "size"] + ["x", "y", "z", "a", "b", "c", "r", "theta", "size", "opacity"] + ["dimensions", "hover_name", "text", "error_x", "error_x_minus"] + ["error_y", "error_y_minus", "error_z", "error_z_minus"] + ["lat", "lon", "locations", "animation_group"] @@ -620,6 +621,8 @@ def infer_config(args, constructor, trace_patch): grouped_attrs.append("marker.symbol") trace_patch = trace_patch.copy() + if "opacity" in args: + trace_patch["marker"] = dict(opacity=args["opacity"]) if "line_group" in args: trace_patch["mode"] = "lines" + ("+markers+text" if args["text"] else "") elif constructor != go.Splom and ( diff --git a/plotly_express/_doc.py b/plotly_express/_doc.py index 30aafb2..f4e92eb 100644 --- a/plotly_express/_doc.py +++ b/plotly_express/_doc.py @@ -91,6 +91,11 @@ "Ignored if `error_z` is `None`.", ], color=[colref, "Values from this column are used to assign color to marks."], + opacity=[ + colref, + "Sets the opacity of the markers in scatter plots such as `scatter()`", + ",`scatter_3d`, `scatter_ternary()`, `scatter_matrix()` and `scatter_polar()`." + ], line_dash=[ colref, "Values from this column are used to assign dash-patterns to lines.", From 5912e39a7cc2469f0b8afc7836a7120cf5c52703 Mon Sep 17 00:00:00 2001 From: ismailuddin Date: Fri, 22 Mar 2019 20:11:00 +0000 Subject: [PATCH 2/4] Removed from `attrables` --- plotly_express/_core.py | 4 +--- plotly_express/_doc.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/plotly_express/_core.py b/plotly_express/_core.py index ebf84b0..17f9e2d 100644 --- a/plotly_express/_core.py +++ b/plotly_express/_core.py @@ -133,8 +133,6 @@ def make_trace_kwargs(args, trace_spec, g, mapping_labels, sizeref, color_range) or len(args["data_frame"][name].unique()) <= 20 ) ] - elif k == 'opacity': - pass elif v or (trace_spec.constructor == go.Histogram and k in ["x", "y"]): if k == "size": if "marker" not in result: @@ -569,7 +567,7 @@ def one_group(x): def infer_config(args, constructor, trace_patch): attrables = ( - ["x", "y", "z", "a", "b", "c", "r", "theta", "size", "opacity"] + ["x", "y", "z", "a", "b", "c", "r", "theta", "size"] + ["dimensions", "hover_name", "text", "error_x", "error_x_minus"] + ["error_y", "error_y_minus", "error_z", "error_z_minus"] + ["lat", "lon", "locations", "animation_group"] diff --git a/plotly_express/_doc.py b/plotly_express/_doc.py index f4e92eb..d4e0214 100644 --- a/plotly_express/_doc.py +++ b/plotly_express/_doc.py @@ -92,7 +92,6 @@ ], color=[colref, "Values from this column are used to assign color to marks."], opacity=[ - colref, "Sets the opacity of the markers in scatter plots such as `scatter()`", ",`scatter_3d`, `scatter_ternary()`, `scatter_matrix()` and `scatter_polar()`." ], From 63a87040798d703ec12be6129580e43490c67435 Mon Sep 17 00:00:00 2001 From: ismailuddin Date: Fri, 22 Mar 2019 20:24:31 +0000 Subject: [PATCH 3/4] Added None check --- plotly_express/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly_express/_core.py b/plotly_express/_core.py index 17f9e2d..fc6109b 100644 --- a/plotly_express/_core.py +++ b/plotly_express/_core.py @@ -619,7 +619,7 @@ def infer_config(args, constructor, trace_patch): grouped_attrs.append("marker.symbol") trace_patch = trace_patch.copy() - if "opacity" in args: + if "opacity" in args and not None: trace_patch["marker"] = dict(opacity=args["opacity"]) if "line_group" in args: trace_patch["mode"] = "lines" + ("+markers+text" if args["text"] else "") From 1bd7c107c1bf16e67363228c4ae5e8a6a06eaa06 Mon Sep 17 00:00:00 2001 From: ismailuddin Date: Fri, 22 Mar 2019 20:28:15 +0000 Subject: [PATCH 4/4] Adjust docstring --- plotly_express/_core.py | 2 +- plotly_express/_doc.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plotly_express/_core.py b/plotly_express/_core.py index fc6109b..17f9e2d 100644 --- a/plotly_express/_core.py +++ b/plotly_express/_core.py @@ -619,7 +619,7 @@ def infer_config(args, constructor, trace_patch): grouped_attrs.append("marker.symbol") trace_patch = trace_patch.copy() - if "opacity" in args and not None: + if "opacity" in args: trace_patch["marker"] = dict(opacity=args["opacity"]) if "line_group" in args: trace_patch["mode"] = "lines" + ("+markers+text" if args["text"] else "") diff --git a/plotly_express/_doc.py b/plotly_express/_doc.py index d4e0214..44301e1 100644 --- a/plotly_express/_doc.py +++ b/plotly_express/_doc.py @@ -92,8 +92,7 @@ ], color=[colref, "Values from this column are used to assign color to marks."], opacity=[ - "Sets the opacity of the markers in scatter plots such as `scatter()`", - ",`scatter_3d`, `scatter_ternary()`, `scatter_matrix()` and `scatter_polar()`." + "(number, between 0 and 1) Sets the opacity for markers." ], line_dash=[ colref,