Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Opacity feature #22

Merged
merged 4 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plotly_express/_chart_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def scatter(
x=None,
y=None,
color=None,
opacity=None,
symbol=None,
size=None,
hover_name=None,
Expand Down Expand Up @@ -325,6 +326,7 @@ def scatter_3d(
y=None,
z=None,
color=None,
opacity=None,
symbol=None,
size=None,
text=None,
Expand Down Expand Up @@ -416,6 +418,7 @@ def scatter_ternary(
b=None,
c=None,
color=None,
opacity=None,
symbol=None,
size=None,
text=None,
Expand Down Expand Up @@ -483,6 +486,7 @@ def scatter_polar(
r=None,
theta=None,
color=None,
opacity=None,
symbol=None,
size=None,
hover_name=None,
Expand Down Expand Up @@ -774,6 +778,7 @@ def scatter_matrix(
data_frame,
dimensions=None,
color=None,
opacity=None,
symbol=None,
size=None,
category_orders={},
Expand Down
7 changes: 5 additions & 2 deletions plotly_express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions plotly_express/_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll tweak this wording a bit. To match the rest it should be something like (number between 0 and 1) Sets the opacity of markers. (no need to enumerate the function types as this shows up in the individual doc strings of those functions.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted to keep it more inline, feel free to change as necessary!

",`scatter_3d`, `scatter_ternary()`, `scatter_matrix()` and `scatter_polar()`."
],
line_dash=[
colref,
"Values from this column are used to assign dash-patterns to lines.",
Expand Down