Skip to content

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 9 commits into from
Oct 31, 2016
Prev Previous commit
Next Next commit
Replaced plot() calls with scatter() and vlines() calls
  • Loading branch information
DrNightmare committed Oct 30, 2016
commit 62c17168deced84ac824cf8854913c08c145fc8d
20 changes: 8 additions & 12 deletions examples/statistics/customized_violin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ def set_axis_style(ax, labels):
quartile1, medians, quartile3 = np.percentile(data, [25, 50, 75], axis=1)
inter_quartile_ranges = np.vstack([quartile1, quartile3]).T
Copy link
Member

Choose a reason for hiding this comment

The 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)
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
for i, median in enumerate(medians):
ax2.plot([i + 1, i + 1], whiskers[i], '-', color='black', linewidth=1)
ax2.plot(
[i + 1, i + 1], inter_quartile_ranges[i], '-', color='black',
linewidth=5)
ax2.plot(
i + 1, median, 'o', color='white',
markersize=6, markeredgecolor='none')
whiskersMin, whiskersMax = list(zip(*whiskers))
# plot medians as points,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove these comments, probably

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm right, will remove these comments and the unused variable

# whiskers as thin lines, quartiles as fat lines
inds = np.arange(1, len(medians) + 1)
ax2.scatter(inds, medians, marker='o', color='white', s=30, zorder=3)
ax2.vlines(inds, quartile1, quartile3, color='k', linestyle='-', lw=5)
ax2.vlines(inds, whiskersMin, whiskersMax, color='k', linestyle='-', lw=1)

# set style for the axes
labels = ['A', 'B', 'C', 'D'] # labels
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name = comment

Expand Down