I am trying to make two sets of box plots using Matplotlib. I want each set of box plot filled (and points and whiskers) in a different color. So basically there will be two colors on the plot
My code is below, would be great if you can help make these plots in color. d0
and d1
are each list of lists of data. I want the set of box plots made with data in d0
in one color, and the set of box plots with data in d1
in another color.
plt.boxplot(d0, widths = 0.1)
plt.boxplot(d1, widths = 0.1)
You can change the color of a box plot using
setp
on the returned value fromboxplot()
as follows:This would display as follows:
To colorize the boxplot, you need to first use the
patch_artist=True
keyword to tell it that the boxes are patches and not just paths. Then you have two main options here:...props
keyword argument, e.g.boxprops=dict(facecolor="red")
. For all keyword arguments, refer to the documentationplt.setp(item, properties)
functionality to set the properties of the boxes, whiskers, fliers, medians, caps.item.set_<property>(...)
on them individually. This option is detailed in an answer to the following question: python matplotlib filled boxplots, where it allows to change the color of the individual boxes separately.The complete example, showing options 1 and 2:
This question seems to be similar to that one (Face pattern for boxes in boxplots) I hope this code solves your problem