Matt Hancock
Matt Hancock

Reputation: 4039

Matplotlib's violinplot doesn't follow rcParam

This is matplotlib version 1.5.0. I cannot seem to set the rcParams in a way that violinpot will obey the facecolors. I've set both the prop_cyle and the facecolor keys for axes and patch respectively to no avail. For example the code below ....

import matplotlib
from cycler import cycler


matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['pink','purple','salmon'])
matplotlib.rcParams['patch.facecolor'] = 'pink'
matplotlib.rcParams['patch.edgecolor'] = 'blue'

import matplotlib.pyplot as plt
from numpy.random import randn

fig = plt.figure(figsize=(12,6))

X = randn(100)

ax = fig.add_subplot(121)
for i in range(3):
    ax.hist(X+2*i)

ax = fig.add_subplot(122)
for i in range(3):
    ax.violinplot(X+2*i)

plt.show()

.... produces:

no image description here

It's hard to discern from the picture, but the edge color does in fact get set to blue in the violinplot. There seems to be a default alpha setting with violinplot which makes this not quite apparent. However, the facecolors obviously remain at the default. Why is this, and can I force it to use the rcParams values? I realize that I can set the facecolors manually after plotting, but I'd rather just have the plots obey the default.

Upvotes: 1

Views: 204

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40697

the red and yellow colors are hard-coded in the code for violonplot unfortunately.

bodies += [fill(stats['coords'],
                            -vals + pos,
                            vals + pos,
                            facecolor='y',
                            alpha=0.3)]
(...)
artists['cmeans'] = perp_lines(means, pmins, pmaxes, colors='r')

I suggest you drop a feature request on the matplotlib github

Upvotes: 1

Related Questions