-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
Add quantile feature to forestplot ridgeplot #1047
Merged
ahartikainen
merged 7 commits into
arviz-devs:master
from
percygautam:ridgeplot_quantiles
Feb 13, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d1e2f11
Add quantile feature to forestplot ridgeplot
percygautam 7b733f0
Changed the figsize
percygautam 94417f4
added quantile feature to bokeh forestplot
percygautam 155d6cc
changed the figsize of all the ridgeplots(with or without quantiles)
percygautam a57fd9f
Merge branch 'master' into ridgeplot_quantiles
percygautam cc9440c
added the change to changelog
percygautam 028b2ff
Merge branch 'master' into ridgeplot_quantiles
percygautam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ def plot_forest( | |
ridgeplot_overlap, | ||
ridgeplot_alpha, | ||
ridgeplot_kind, | ||
ridgeplot_quantiles, | ||
textsize, | ||
ess, | ||
r_hat, | ||
|
@@ -52,7 +53,10 @@ def plot_forest( | |
) | ||
|
||
if figsize is None: | ||
figsize = (min(12, sum(width_ratios) * 2), plot_handler.fig_height()) | ||
if kind == "ridgeplot": | ||
figsize = (min(14, sum(width_ratios) * 4), plot_handler.fig_height() * 1.2) | ||
else: | ||
figsize = (min(12, sum(width_ratios) * 2), plot_handler.fig_height()) | ||
|
||
(figsize, _, titlesize, xt_labelsize, auto_linewidth, auto_markersize) = _scale_fig_size( | ||
figsize, textsize, 1.1, 1 | ||
|
@@ -98,7 +102,12 @@ def plot_forest( | |
) | ||
elif kind == "ridgeplot": | ||
plot_handler.ridgeplot( | ||
ridgeplot_overlap, linewidth, ridgeplot_alpha, ridgeplot_kind, axes[0] | ||
ridgeplot_overlap, | ||
linewidth, | ||
ridgeplot_alpha, | ||
ridgeplot_kind, | ||
ridgeplot_quantiles, | ||
axes[0], | ||
) | ||
else: | ||
raise TypeError( | ||
|
@@ -230,7 +239,7 @@ def display_multiple_ropes(self, rope, ax, y, linewidth, rope_var): | |
) | ||
return ax | ||
|
||
def ridgeplot(self, mult, linewidth, alpha, ridgeplot_kind, ax): | ||
def ridgeplot(self, mult, linewidth, alpha, ridgeplot_kind, ridgeplot_quantiles, ax): | ||
"""Draw ridgeplot for each plotter. | ||
|
||
Parameters | ||
|
@@ -251,7 +260,7 @@ def ridgeplot(self, mult, linewidth, alpha, ridgeplot_kind, ax): | |
alpha = 1.0 | ||
zorder = 0 | ||
for plotter in self.plotters.values(): | ||
for x, y_min, y_max, color in plotter.ridgeplot(mult, ridgeplot_kind): | ||
for x, y_min, y_max, y_q, color in plotter.ridgeplot(mult, ridgeplot_kind): | ||
if alpha == 0: | ||
border = color | ||
facecolor = "None" | ||
|
@@ -269,9 +278,21 @@ def ridgeplot(self, mult, linewidth, alpha, ridgeplot_kind, ax): | |
zorder=zorder, | ||
) | ||
else: | ||
ax.plot(x, y_max, "-", linewidth=linewidth, color=border, zorder=zorder) | ||
ax.plot(x, y_min, "-", linewidth=linewidth, color=border, zorder=zorder) | ||
ax.fill_between(x, y_min, y_max, alpha=alpha, color=color, zorder=zorder) | ||
if ridgeplot_quantiles is not None: | ||
idx = [np.sum(y_q < quant) for quant in ridgeplot_quantiles] | ||
ax.fill_between( | ||
x, | ||
y_min, | ||
y_max, | ||
where=np.isin(x, x[idx], invert=True, assume_unique=True), | ||
alpha=alpha, | ||
color=color, | ||
zorder=zorder, | ||
) | ||
else: | ||
ax.plot(x, y_max, "-", linewidth=linewidth, color=border, zorder=zorder) | ||
ax.plot(x, y_min, "-", linewidth=linewidth, color=border, zorder=zorder) | ||
ax.fill_between(x, y_min, y_max, alpha=alpha, color=color, zorder=zorder) | ||
zorder -= 1 | ||
return ax | ||
|
||
|
@@ -484,7 +505,7 @@ def treeplot(self, qlist, credible_interval): | |
|
||
def ridgeplot(self, mult, ridgeplot_kind): | ||
"""Get data for each ridgeplot for the variable.""" | ||
xvals, yvals, pdfs, colors = [], [], [], [] | ||
xvals, yvals, pdfs, pdfs_q, colors = [], [], [], [], [] | ||
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. this could be
but it is not that important, so no need to change it |
||
for y, *_, values, color in self.iterator(): | ||
yvals.append(y) | ||
colors.append(color) | ||
|
@@ -502,15 +523,17 @@ def ridgeplot(self, mult, ridgeplot_kind): | |
x = x[:-1] | ||
elif kind == "density": | ||
density, lower, upper = _fast_kde(values) | ||
density_q = density.cumsum() / density.sum() | ||
x = np.linspace(lower, upper, len(density)) | ||
|
||
xvals.append(x) | ||
pdfs.append(density) | ||
pdfs_q.append((density_q)) | ||
|
||
scaling = max(np.max(j) for j in pdfs) | ||
for y, x, pdf, color in zip(yvals, xvals, pdfs, colors): | ||
for y, x, pdf, pdf_q, color in zip(yvals, xvals, pdfs, pdfs_q, colors): | ||
y = y * np.ones_like(x) | ||
yield x, y, mult * pdf / scaling + y, color | ||
yield x, y, mult * pdf / scaling + y, pdf_q, color | ||
|
||
def ess(self): | ||
"""Get effective n data for the variable.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ohh, sorry I misread your previous example. This is OK