Matplotlib > Box and whisker plots

Name
Code
Output
gaussian = numpy.random.normal(loc=1.0, scale=0.1,size = 1000)
matplotlib.pyplot.boxplot(gaussian)
matplotlib.pyplot.show()

       
           Box and whisker plot (basic)
       
    
# Data
gauss1 = numpy.random.normal(loc=1.0, scale=10.0,size = 1000)
gauss2 = numpy.random.normal(loc=5.0, scale=7.0,size = 1000)
gauss3 = numpy.random.normal(loc=10.0, scale=5.0,size = 1000)
# New Figure
fig = matplotlib.pyplot.figure(figsize=(7,4),facecolor='silver')
# New Axes
ax = fig.add_subplot(111,facecolor='azure')
# Add grid
ax.grid(color='b', linestyle='-', linewidth=0.5)
# Plot the data
bw_plot = ax.boxplot([gauss1,gauss2,gauss3],labels=['A', 'B', 'C'],patch_artist=True)
ax.set(title="Plot title", xlabel="x axis", ylabel="y axis")
for item in ['boxes', 'whiskers','medians', 'means','caps','fliers']:
    matplotlib.pyplot.setp(bw_plot[item], color='blue',linewidth=2)
for box_patch in bw_plot['boxes']:
        box_patch.set(facecolor='orange') 
# Fit the plot layout
matplotlib.pyplot.tight_layout()
# Show the plot
matplotlib.pyplot.show()

       
           Box and whisker plot (customized)