-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Updated violin plot example as per suggestions in issue #7251 #7360
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
08db92d
Updated example as per suggestions in issue #7251
DrNightmare becbfa4
Fixed ordering of parameters to np.clip()
DrNightmare 14cd6cf
Made variable names more meaningful
DrNightmare 03946d4
Replaced use of zip with call to transpose
DrNightmare 8044e9d
Changed variable 'tmp' to 'quartiles' and slightly altered transpose …
DrNightmare 88a8c2e
Fixed recalculation of interquartile ranges
DrNightmare 62c1716
Replaced plot() calls with scatter() and vlines() calls
DrNightmare 9f4bbdd
Removed unused variable and comments
DrNightmare b3ce73b
Removed unnecessary comments
DrNightmare 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
Fixed recalculation of interquartile ranges
- Loading branch information
commit 88a8c2e98b916d4ada3bd392ab5c4d3ece1ec166
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -18,14 +18,11 @@ | |
import numpy as np | ||
|
||
|
||
def adjacent_values(vals): | ||
q1, q3 = np.percentile(vals, [25, 75]) | ||
inter_quartile_range = q3 - q1 | ||
|
||
upper_adjacent_value = q3 + inter_quartile_range * 1.5 | ||
def adjacent_values(vals, q1, q3): | ||
upper_adjacent_value = q3 + (q3 - q1) * 1.5 | ||
upper_adjacent_value = np.clip(upper_adjacent_value, q3, vals[-1]) | ||
|
||
lower_adjacent_value = q1 - inter_quartile_range * 1.5 | ||
lower_adjacent_value = q1 - (q3 - q1) * 1.5 | ||
lower_adjacent_value = np.clip(lower_adjacent_value, vals[0], q1) | ||
return [lower_adjacent_value, upper_adjacent_value] | ||
|
||
|
@@ -62,10 +59,11 @@ def set_axis_style(ax, labels): | |
pc.set_edgecolor('black') | ||
pc.set_alpha(1) | ||
|
||
quartiles = (np.percentile(data, [25, 50, 75], axis=1)) | ||
medians = quartiles[1] | ||
inter_quartile_ranges = quartiles[[0, 2]].T | ||
whiskers = [adjacent_values(sorted_array) for sorted_array in data] | ||
quartile1, medians, quartile3 = np.percentile(data, [25, 50, 75], axis=1) | ||
inter_quartile_ranges = np.vstack([quartile1, quartile3]).T | ||
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. Pretty sure this variable is no longer used and so can be removed |
||
whiskers = [ | ||
adjacent_values(sorted_array, q1, q3) | ||
for sorted_array, q1, q3 in zip(data, quartile1, quartile3)] | ||
|
||
# plot whiskers as thin lines, quartiles as fat lines, | ||
# and medians as points | ||
|
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.
Probabky doesn't need to be bracketed [], wonder if it can be used to remove zip* stuff in the unpacking...
Uh oh!
There was an error while loading. Please reload this page.
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.
To avoid the unpacking, I could also optionally make 'whiskers' an np.array and then do:
whiskersMin, whiskersMax = whiskers[:, 0], whiskers[:, 1]
Irrespective of whether I do this or not, the brackets can be removed
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.
Then I think it makes sense to do that.
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.
Yes, updated in latest commit