diff --git a/.gitignore b/.gitignore index 9b775afc5d67..b56c466ef4e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +######################################### +# OS-specific temporary and backup files +.DS_Store + ######################################### # Editor temporary/working/backup files # .#* @@ -8,6 +12,7 @@ *.kdev4 .project .pydevproject +.swp # Compiled source # ################### diff --git a/doc/.DS_Store b/doc/.DS_Store new file mode 100644 index 000000000000..d04617eddd91 Binary files /dev/null and b/doc/.DS_Store differ diff --git a/doc/_static/boxplot_explanation.png b/doc/_static/boxplot_explanation.png new file mode 100644 index 000000000000..feacb39d2443 Binary files /dev/null and b/doc/_static/boxplot_explanation.png differ diff --git a/doc/faq/howto_faq.rst b/doc/faq/howto_faq.rst index c845b1fcdfcc..42ff1bc16aae 100644 --- a/doc/faq/howto_faq.rst +++ b/doc/faq/howto_faq.rst @@ -478,6 +478,18 @@ though we have made significant progress towards supporting blocking events. able to create new figures and raise them in a subsequent call to ``show`` after closing the figures from a previous call to ``show``. +.. _howto-boxplot_violinplot: + +Interpreting box plots and violin plots +----------------------------------- + +Tukey's `box plots `_ (Robert McGill, John W. Tukey and Wayne A. Larsen: "The American Statistician" Vol. 32, No. 1, Feb., 1978, pp. 12-16) are statistical plots that provide useful information about the data distribution such as skewness. However, bar plots with error bars are still the common standard in most scientific literature, and thus, the interpretation of box plots can be challenging for the unfamiliar reader. The figure below illustrates the different visual features of a box plot. + +.. figure:: ../_static/boxplot_explanation.png + +`Violin plots `_ are closely related to box plots but add useful information such as the distribution of the sample data (density trace). +Violin plots were added in matplotlib 1.4. + .. _howto-contribute: diff --git a/examples/statistics/boxplot_color_demo.py b/examples/statistics/boxplot_color_demo.py new file mode 100644 index 000000000000..cc1a9f5d6b58 --- /dev/null +++ b/examples/statistics/boxplot_color_demo.py @@ -0,0 +1,43 @@ +# Box plots with custom fill colors + +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)] + +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 + +# 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 + +# fill with colors +colors = ['pink', 'lightblue', 'lightgreen'] +for bplot in (bplot1, bplot2): + for patch, color in zip(bplot['boxes'], colors): + patch.set_facecolor(color) + +# 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'], + ) + +plt.show() + + diff --git a/examples/statistics/boxplot_vs_violin_demo.py b/examples/statistics/boxplot_vs_violin_demo.py new file mode 100644 index 000000000000..b2a654828a25 --- /dev/null +++ b/examples/statistics/boxplot_vs_violin_demo.py @@ -0,0 +1,42 @@ +# 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. + +import matplotlib.pyplot as plt +import numpy as np + +fig, axes = plt.subplots(nrows=1,ncols=2, figsize=(12,5)) + +# generate some random test data +all_data = [np.random.normal(0, std, 100) for std in range(6, 10)] + +# plot violin plot +axes[0].violinplot(all_data, + showmeans=False, + showmedians=True + ) +axes[0].set_title('violin plot') + +# plot box plot +axes[1].boxplot(all_data) +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') + +# add x-tick labels +plt.setp(axes, xticks=[y+1 for y in range(len(all_data))], + xticklabels=['x1', 'x2', 'x3', 'x4'], + ) + +plt.show() \ No newline at end of file