-
-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve issue #992 : Integrate point_estimate with rcParam #994
Changes from 5 commits
eb0af7a
1c9f1c9
3f336fe
25083ba
c4029fd
18a1dc4
f36ae5e
b2f600d
1d6f174
009145d
ec3374b
49ab1e5
b344445
3a8c621
dc138d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
from bokeh.models.annotations import Title | ||
|
||
from . import backend_kwarg_defaults, backend_show | ||
from ...kdeplot import _fast_kde | ||
from ...plot_utils import _create_axes_grid, make_label | ||
from ...plot_utils import ( | ||
make_label, | ||
_create_axes_grid, | ||
calculate_point_estimate, | ||
_fast_kde, | ||
) | ||
from ....stats import hpd | ||
from ....stats.stats_utils import histogram | ||
|
||
|
@@ -185,11 +189,8 @@ def _d_helper( | |
ax.diamond(xmin, 0, line_color="black", fill_color=color, size=markersize) | ||
ax.diamond(xmax, 0, line_color="black", fill_color=color, size=markersize) | ||
|
||
est = calculate_point_estimate(point_estimate, vec, bw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move that inside the if, there is no need to calculate the point value if it will not be plotted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, makes sense. Will do. |
||
if point_estimate is not None: | ||
if point_estimate == "mean": | ||
est = np.mean(vec) | ||
elif point_estimate == "median": | ||
est = np.median(vec) | ||
ax.circle(est, 0, fill_color=color, line_color="black", size=markersize) | ||
|
||
_title = Title() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,13 @@ | |
from scipy.stats import mode | ||
|
||
from . import backend_kwarg_defaults, backend_show | ||
from ...kdeplot import plot_kde, _fast_kde | ||
from ...kdeplot import plot_kde | ||
from ...plot_utils import ( | ||
make_label, | ||
_create_axes_grid, | ||
format_sig_figs, | ||
round_num, | ||
calculate_point_estimate, | ||
) | ||
from ....stats import hpd | ||
|
||
|
@@ -187,21 +188,9 @@ def display_rope(max_data): | |
ax.text(x=vals, y=[max_data * 0.2, max_data * 0.2], text=list(map(str, vals)), **text_props) | ||
|
||
def display_point_estimate(max_data): | ||
point_value = calculate_point_estimate(point_estimate, values, bw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment, here it means after the if instead of inside though |
||
if not point_estimate: | ||
return | ||
if point_estimate not in ("mode", "mean", "median"): | ||
raise ValueError("Point Estimate should be in ('mode','mean','median')") | ||
if point_estimate == "mean": | ||
point_value = values.mean() | ||
elif point_estimate == "mode": | ||
if isinstance(values[0], float): | ||
density, lower, upper = _fast_kde(values, bw=bw) | ||
x = np.linspace(lower, upper, len(density)) | ||
point_value = x[np.argmax(density)] | ||
else: | ||
point_value = mode(values)[0][0] | ||
elif point_estimate == "median": | ||
point_value = np.median(values) | ||
sig_figs = format_sig_figs(point_value, round_to) | ||
point_text = "{point_estimate}={point_value:.{sig_figs}g}".format( | ||
point_estimate=point_estimate, point_value=point_value, sig_figs=sig_figs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,12 @@ | |
|
||
from . import backend_show | ||
from ....stats import hpd | ||
from ...kdeplot import _fast_kde | ||
from ...plot_utils import _create_axes_grid, make_label | ||
from ...plot_utils import ( | ||
make_label, | ||
_create_axes_grid, | ||
calculate_point_estimate, | ||
_fast_kde, | ||
) | ||
|
||
|
||
def plot_density( | ||
|
@@ -115,8 +119,9 @@ def _d_helper( | |
Size of markers | ||
credible_interval : float | ||
Credible intervals. Defaults to 0.94 | ||
point_estimate : str or None | ||
'mean' or 'median' | ||
point_estimate : Optional[str] | ||
Plot point estimate per variable. Values should be 'mean', 'median', 'mode' or None. | ||
Defaults to 'auto' i.e. it falls back to default set in rcParams. | ||
shade : float | ||
Alpha blending value for the shaded area under the curve, between 0 (no shade) and 1 | ||
(opaque). Defaults to 0. | ||
|
@@ -155,11 +160,8 @@ def _d_helper( | |
ax.plot(xmin, 0, hpd_markers, color=color, markeredgecolor="k", markersize=markersize) | ||
ax.plot(xmax, 0, hpd_markers, color=color, markeredgecolor="k", markersize=markersize) | ||
|
||
est = calculate_point_estimate(point_estimate, vec, bw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inside the if |
||
if point_estimate is not None: | ||
if point_estimate == "mean": | ||
est = np.mean(vec) | ||
elif point_estimate == "median": | ||
est = np.median(vec) | ||
ax.plot(est, 0, "o", color=color, markeredgecolor="k", markersize=markersize) | ||
|
||
ax.set_yticks([]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
|
||
from . import backend_show | ||
from ....stats import hpd | ||
from ...kdeplot import plot_kde, _fast_kde | ||
from ...kdeplot import plot_kde | ||
from ...plot_utils import ( | ||
make_label, | ||
_create_axes_grid, | ||
format_sig_figs, | ||
round_num, | ||
calculate_point_estimate, | ||
) | ||
|
||
|
||
|
@@ -179,21 +180,9 @@ def display_rope(): | |
ax.text(vals[1], plot_height * 0.2, vals[1], weight="semibold", **text_props) | ||
|
||
def display_point_estimate(): | ||
point_value = calculate_point_estimate(point_estimate, values, bw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after the if |
||
if not point_estimate: | ||
return | ||
if point_estimate not in ("mode", "mean", "median"): | ||
raise ValueError("Point Estimate should be in ('mode','mean','median')") | ||
if point_estimate == "mean": | ||
point_value = values.mean() | ||
elif point_estimate == "mode": | ||
if isinstance(values[0], float): | ||
density, lower, upper = _fast_kde(values, bw=bw) | ||
x = np.linspace(lower, upper, len(density)) | ||
point_value = x[np.argmax(density)] | ||
else: | ||
point_value = mode(values)[0][0] | ||
elif point_estimate == "median": | ||
point_value = np.median(values) | ||
sig_figs = format_sig_figs(point_value, round_to) | ||
point_text = "{point_estimate}={point_value:.{sig_figs}g}".format( | ||
point_estimate=point_estimate, point_value=point_value, sig_figs=sig_figs | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also move
_fast_kde_2d
next to_fast_kde
, sorry for not saying it explicitly before