0

I am struggling to plot a boxplot for custom column names of dataframe and afterwards fill them with custom different colors.

df=pd.DataFrame([[1,2,3],[3,4,3],[3,4,3]],columns=['x','y','z'])
df.boxplot(column=['x', 'y'])
plt.show()

I can't customize colours of my boxplots. Is there any way how to do it with simple code?

FedorT54
  • 11
  • 3
  • See [change-the-facecolor-of-boxplot-in-pandas](https://stackoverflow.com/questions/39297093/change-the-facecolor-of-boxplot-in-pandas) for a better answer. – JohanC May 30 '20 at 18:14

1 Answers1

0

Try using this:

df = pd.DataFrame([[1,2,3],[3,4,3],[3,4,3]], columns=['x','y','z'])
box = plt.boxplot([df['x'], df['y']], patch_artist=True)
colors = ['blue', 'green']
for patch, color in zip(box['boxes'], colors):
    patch.set_facecolor(color)
plt.show()
NYC Coder
  • 7,424
  • 2
  • 11
  • 24