Is there a way to change the color of the violin
plots in matplotlib?
The default color is this "brownish" color, which is not too bad, but I'd like to color e.g., the first 3 violins differently to highlight them. I don't find any parameter in the documentation. Any ideas or hacks to color the violins differently?
matplotlib.pyplot.violinplot()
says it returns:Methods of
PolyCollection
s include:set_color(c)
which sets both the facecolor and edgecolor,set_facecolor(c)
andset_edgecolor(c)
all of which take a "matplotlib color arg or sequence of rgba tuples"So, it looks like you could just loop through the result's body list and modify the facecolor of each:
It is a bit strange though that you can't set this when creating it like the common plot types. I'd guess it's probably because the operation creates so many bits (the aforementioned
PolyCollection
along with 5 otherLineCollections
), that additional arguments would be ambiguous.