diff --git a/examples/showcase/bachelors_degrees_by_gender.py b/examples/showcase/bachelors_degrees_by_gender.py index fb5132cc4224..d891fbe52153 100644 --- a/examples/showcase/bachelors_degrees_by_gender.py +++ b/examples/showcase/bachelors_degrees_by_gender.py @@ -1,3 +1,11 @@ +""" +A graph of multiple time series which demonstrates extensive custom +styling of plot frame, tick lines and labels, and line graph properties. + +Also demonstrates the custom placement of text labels along the right edge +as an alternative to a conventional legend. +""" + import matplotlib.pyplot as plt from matplotlib.mlab import csv2rec from matplotlib.cbook import get_sample_data diff --git a/examples/statistics/boxplot_color_demo.py b/examples/statistics/boxplot_color_demo.py index e16bf3822ea2..474f427d76eb 100644 --- a/examples/statistics/boxplot_color_demo.py +++ b/examples/statistics/boxplot_color_demo.py @@ -1,24 +1,36 @@ -# Box plots with custom fill colors +"""Box plots with custom fill colors. + +This plot illustrates how to create two types of box plots +(rectangular and notched), and how to fill them with custom +colors by accessing the properties of the artists of the +box plots. Additionally, the ``labels`` parameter is used to +provide x-tick labels for each sample. +""" import matplotlib.pyplot as plt import numpy as np # Random test data np.random.seed(123) -all_data = [np.random.normal(0, std, 100) for std in range(1, 4)] +all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)] +labels = ['x1', 'x2', 'x3'] fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5)) # rectangular box plot bplot1 = axes[0].boxplot(all_data, - vert=True, # vertical box aligmnent - patch_artist=True) # fill with color + vert=True, # vertical box alignment + patch_artist=True, # fill with color + labels=labels) # will be used to label x-ticks +axes[0].set_title('Rectangular box plot') # notch shape box plot bplot2 = axes[1].boxplot(all_data, notch=True, # notch shape - vert=True, # vertical box aligmnent - patch_artist=True) # fill with color + vert=True, # vertical box alignment + patch_artist=True, # fill with color + labels=labels) # will be used to label x-ticks +axes[1].set_title('Notched box plot') # fill with colors colors = ['pink', 'lightblue', 'lightgreen'] @@ -29,12 +41,7 @@ # adding horizontal grid lines for ax in axes: ax.yaxis.grid(True) - ax.set_xticks([y+1 for y in range(len(all_data))], ) - ax.set_xlabel('xlabel') - ax.set_ylabel('ylabel') - -# add x-tick labels -plt.setp(axes, xticks=[y+1 for y in range(len(all_data))], - xticklabels=['x1', 'x2', 'x3', 'x4']) + ax.set_xlabel('Three separate samples') + ax.set_ylabel('Observed values') plt.show() diff --git a/examples/statistics/boxplot_vs_violin_demo.py b/examples/statistics/boxplot_vs_violin_demo.py index acec4f00ceb5..c4150e5db7bb 100644 --- a/examples/statistics/boxplot_vs_violin_demo.py +++ b/examples/statistics/boxplot_vs_violin_demo.py @@ -1,13 +1,15 @@ -# Box plot - violin plot comparison -# -# Note that although violin plots are closely related to Tukey's (1977) box plots, -# they add useful information such as the distribution of the sample data (density trace). -# -# By default, box plots show data points outside 1.5 x the inter-quartile range as outliers -# above or below the whiskers wheras violin plots show the whole range of the data. -# -# Violin plots require matplotlib >= 1.4. +"""Box plot - violin plot comparison. +Note that although violin plots are closely related to Tukey's (1977) box +plots, they add useful information such as the distribution of the sample +data (density trace). + +By default, box plots show data points outside 1.5 x the inter-quartile range +as outliers above or below the whiskers whereas violin plots show the whole +range of the data. + +Violin plots require matplotlib >= 1.4. +""" import matplotlib.pyplot as plt import numpy as np @@ -20,20 +22,20 @@ axes[0].violinplot(all_data, showmeans=False, showmedians=True) -axes[0].set_title('violin plot') +axes[0].set_title('Violin plot') # plot box plot axes[1].boxplot(all_data) -axes[1].set_title('box plot') +axes[1].set_title('Box plot') # adding horizontal grid lines for ax in axes: ax.yaxis.grid(True) - ax.set_xticks([y+1 for y in range(len(all_data))]) - ax.set_xlabel('xlabel') - ax.set_ylabel('ylabel') + ax.set_xticks([y + 1 for y in range(len(all_data))]) + ax.set_xlabel('Four separate samples') + ax.set_ylabel('Observed values') # add x-tick labels -plt.setp(axes, xticks=[y+1 for y in range(len(all_data))], +plt.setp(axes, xticks=[y + 1 for y in range(len(all_data))], xticklabels=['x1', 'x2', 'x3', 'x4']) plt.show()