Skip to content

Instantly share code, notes, and snippets.

@nerevar
Last active June 4, 2016 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerevar/7ef3a840844d22ba2be5 to your computer and use it in GitHub Desktop.
Save nerevar/7ef3a840844d22ba2be5 to your computer and use it in GitHub Desktop.
python neat boxplot #python #matplotlib #boxplot #graph
import matplotlib.pyplot as plt
def draw(data):
bp = plt.boxplot(data,
widths=0.7,
notch=True, # adds median notch
patch_artist=True,
)
plt.grid(axis='y', # set y-axis grid lines
linestyle='--', # use dashed lines
which='major', # only major ticks
color='lightgrey', # line colour
alpha=0.7) # make lines semi-translucent
plt.setp(bp['whiskers'], color='DarkMagenta', linewidth=1.5)
plt.setp(bp['caps'], color='DarkMagenta', linewidth=1.5)
plt.setp(bp['boxes'], color='DarkMagenta', linewidth=1.5)
plt.setp(bp['fliers'], color='OrangeRed', marker='o', markersize=10)
plt.setp(bp['medians'], color='OrangeRed', linewidth=1.5)
colors = ['lightgreen', 'lightblue', 'tan', 'pink']
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment