Skip to content

Commit

Permalink
Issue justinbois#21, added patch_kwargs to predictive_ecdf and predic…
Browse files Browse the repository at this point in the history
…tive_regression
  • Loading branch information
tomroesch committed Feb 20, 2020
1 parent a0423da commit 69cd70c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions bebi103/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,12 @@ def predictive_ecdf(
data_color="orange",
data_staircase=True,
data_size=2,
data_alpha=1.,
x=None,
discrete=False,
line_alpha=1.,
p=None,
patch_kwargs={},
**kwargs,
):
"""Plot a predictive ECDF from samples.
Expand Down Expand Up @@ -490,14 +493,21 @@ def predictive_ecdf(
data_size : int, default 2
Size of marker (if `data_line` if False) or thickness of line
(if `data_staircase` is True) of plot of data.
data_alpha: float, default 1
Transpararency of the ECDF of the data.
x : Numpy array, default None
Points at which to evaluate the ECDF. If None, points are
automatically generated based on the data range.
discrete : bool, default False
If True, the samples take on discrete values.
line_alpha: float, default 1
Transpararency of the predictive ECDF.
p : bokeh.plotting.Figure instance, or None (default)
If None, create a new figure. Otherwise, populate the existing
figure `p`.
patch_kwargs : dict
Any kwargs to be passed to p.patch() in making the fill of the
histogram.
kwargs
All other kwargs are passed to bokeh.plotting.figure().
Expand Down Expand Up @@ -601,22 +611,23 @@ def predictive_ecdf(
x = df_ecdf["x"]
y1 = df_ecdf[ptile]
y2 = df_ecdf[ptiles_str[-i - 1]]
patch_kwargs['color'] = colors[color][i]
fill_between(
x,
y1,
x,
y2,
p=p,
show_line=False,
patch_kwargs=dict(color=colors[color][i]),
patch_kwargs=patch_kwargs
)

# The median as a solid line
if discrete:
x, y = cdf_to_staircase(df_ecdf["x"], df_ecdf["50"])
else:
x, y = df_ecdf["x"], df_ecdf["50"]
p.line(x, y, line_width=2, color=colors[color][-1])
p.line(x, y, line_width=2, color=colors[color][-1], alpha=line_alpha)

# Overlay data set
if data is not None:
Expand All @@ -633,9 +644,9 @@ def predictive_ecdf(
x_data = unique_x
if data_staircase:
x_data, y_data = cdf_to_staircase(x_data, y_data)
p.line(x_data, y_data, color=data_color, line_width=data_size)
p.line(x_data, y_data, color=data_color, line_width=data_size, alpha=data_alpha)
else:
p.circle(x_data, y_data, color=data_color, size=data_size)
p.circle(x_data, y_data, color=data_color, size=data_size, alpha=data_alpha)

return p

Expand All @@ -647,6 +658,7 @@ def predictive_regression(
diff=False,
percentiles=[80, 60, 40, 20],
color="blue",
patch_kwargs={},
data_kwargs={},
p=None,
**kwargs,
Expand All @@ -673,6 +685,9 @@ def predictive_regression(
One of ['green', 'blue', 'red', 'gray', 'purple', 'orange'].
There are used to make the color scheme of shading of
percentiles.
patch_kwargs : dict
Any kwargs to be passed to p.patch() in making the fill of the
histogram.
data_kwargs : dict
Any kwargs to be passed to p.circle() when plotting the data
points.
Expand Down Expand Up @@ -783,15 +798,15 @@ def predictive_regression(
else:
y1 = df_pred[ptile]
y2 = df_pred[ptiles_str[-i - 1]]

patch_kwargs['fill_color']=colors[color][i]
fill_between(
x1=df_pred["__x"],
x2=df_pred["__x"],
y1=y1,
y2=y2,
p=p,
show_line=False,
patch_kwargs=dict(fill_color=colors[color][i]),
patch_kwargs=patch_kwargs,
)

# The median as a solid line
Expand Down

0 comments on commit 69cd70c

Please sign in to comment.