From 69cd70c8c8a4349f6ddc8b31d35d800aa9e61286 Mon Sep 17 00:00:00 2001 From: Tom Roeschinger Date: Wed, 19 Feb 2020 22:51:50 -0800 Subject: [PATCH] Issue #21, added patch_kwargs to predictive_ecdf and predictive_regression --- bebi103/viz.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bebi103/viz.py b/bebi103/viz.py index a510655..267da6c 100644 --- a/bebi103/viz.py +++ b/bebi103/viz.py @@ -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. @@ -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(). @@ -601,6 +611,7 @@ 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, @@ -608,7 +619,7 @@ def predictive_ecdf( y2, p=p, show_line=False, - patch_kwargs=dict(color=colors[color][i]), + patch_kwargs=patch_kwargs ) # The median as a solid line @@ -616,7 +627,7 @@ def predictive_ecdf( 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: @@ -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 @@ -647,6 +658,7 @@ def predictive_regression( diff=False, percentiles=[80, 60, 40, 20], color="blue", + patch_kwargs={}, data_kwargs={}, p=None, **kwargs, @@ -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. @@ -783,7 +798,7 @@ 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"], @@ -791,7 +806,7 @@ def predictive_regression( 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