Boxplots are common staple features of scientific publications. Colored boxplots are no trouble; however, you may need to use black and white only. In this recipe, we are going to see how to use custom colors with boxplots.
Every function that creates a specific figure returns some values—they are the low-level drawing primitives that constitute the figure. Most of the time, we don't bother to get those return values. However, manipulating those low-level drawing primitives allows some fine-tuning, such as custom color schemes for a box plot.
Making a boxplot appear totally black is a little bit trickier than it should be, as shown in the following script:
import numpy as np import matplotlib.pyplot as plt values = np.random.randn(100) b = plt.boxplot(values) for name, line_list in b.iteritems(): for line in line_list: line.set_color('k') plt.show()
The preceding script produces the following graph: