========================================= Demo of artist customization in box plots ========================================= This example demonstrates how to use the various kwargs to fully customize box plots. The first figure demonstrates how to remove and add individual
()
| 90 | return fig |
| 91 | |
| 92 | def PyplotArtistBoxPlots(): |
| 93 | """ |
| 94 | ========================================= |
| 95 | Demo of artist customization in box plots |
| 96 | ========================================= |
| 97 | |
| 98 | This example demonstrates how to use the various kwargs |
| 99 | to fully customize box plots. The first figure demonstrates |
| 100 | how to remove and add individual components (note that the |
| 101 | mean is the only value not shown by default). The second |
| 102 | figure demonstrates how the styles of the artists can |
| 103 | be customized. It also demonstrates how to set the limit |
| 104 | of the whiskers to specific percentiles (lower right axes) |
| 105 | |
| 106 | A good general reference on boxplots and their history can be found |
| 107 | here: http://vita.had.co.nz/papers/boxplots.pdf |
| 108 | |
| 109 | """ |
| 110 | |
| 111 | import numpy as np |
| 112 | import matplotlib.pyplot as plt |
| 113 | |
| 114 | # fake data |
| 115 | np.random.seed(937) |
| 116 | data = np.random.lognormal(size=(37, 4), mean=1.5, sigma=1.75) |
| 117 | labels = list('ABCD') |
| 118 | fs = 10 # fontsize |
| 119 | |
| 120 | # demonstrate how to toggle the display of different elements: |
| 121 | fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(6, 6), sharey=True) |
| 122 | axes[0, 0].boxplot(data, labels=labels) |
| 123 | axes[0, 0].set_title('Default', fontsize=fs) |
| 124 | |
| 125 | axes[0, 1].boxplot(data, labels=labels, showmeans=True) |
| 126 | axes[0, 1].set_title('showmeans=True', fontsize=fs) |
| 127 | |
| 128 | axes[0, 2].boxplot(data, labels=labels, showmeans=True, meanline=True) |
| 129 | axes[0, 2].set_title('showmeans=True,\nmeanline=True', fontsize=fs) |
| 130 | |
| 131 | axes[1, 0].boxplot(data, labels=labels, showbox=False, showcaps=False) |
| 132 | tufte_title = 'Tufte Style \n(showbox=False,\nshowcaps=False)' |
| 133 | axes[1, 0].set_title(tufte_title, fontsize=fs) |
| 134 | |
| 135 | axes[1, 1].boxplot(data, labels=labels, notch=True, bootstrap=10000) |
| 136 | axes[1, 1].set_title('notch=True,\nbootstrap=10000', fontsize=fs) |
| 137 | |
| 138 | axes[1, 2].boxplot(data, labels=labels, showfliers=False) |
| 139 | axes[1, 2].set_title('showfliers=False', fontsize=fs) |
| 140 | |
| 141 | for ax in axes.flatten(): |
| 142 | ax.set_yscale('log') |
| 143 | ax.set_yticklabels([]) |
| 144 | |
| 145 | fig.subplots_adjust(hspace=0.4) |
| 146 | return fig |
| 147 | |
| 148 | def ArtistBoxplot2(): |
| 149 |