Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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