Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

seaborn boxplot change filling

import matplotlib.pyplot as plt
import seaborn as sns

fig,(ax1,ax2) = plt.subplots(2)

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")

sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set1", ax=ax1)
sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set1", ax=ax2)

for i,artist in enumerate(ax2.artists):
    # Set the linecolor on the artist to the facecolor, and set the facecolor to None
    col = artist.get_facecolor()
    artist.set_edgecolor(col)
    artist.set_facecolor('None')

    # Each box has 6 associated Line2D objects (to make the whiskers, fliers, etc.)
    # Loop over them here, and use the same colour as above
    for j in range(i*6,i*6+6):
        line = ax2.lines[j]
        line.set_color(col)
        line.set_mfc(col)
        line.set_mec(col)

# Also fix the legend
for legpatch in ax2.get_legend().get_patches():
    col = legpatch.get_facecolor()
    legpatch.set_edgecolor(col)
    legpatch.set_facecolor('None')

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: cv2 and PIL BRG to RGB 
Python :: python post request binary file 
Python :: get processor model in python 
Python :: python list sort key lambda on equal other function 
Python :: python string ignore characters 
Python :: python match case example 
Python :: legend ax matplotlib 
Python :: create django app 
Python :: splitting on basis of regex python 
Python :: Connect to MySQL Using Connector Python C Extension 
Python :: python tkinter plot points 
Python :: 2 plater die game in python 
Python :: scikit learn decistion tree 
Python :: pandas array of dataframes 
Python :: UserWarning: Failed to initialize NumPy: numpy.core.multiarray failed to import (Triggered internally at 
Python :: python sum certain postions of array 
Python :: error:pip.subprocessor:command errored out with exit status 1: 
Python :: torch tensor equal to 
Python :: pip ne marche pas 
Python :: django login required class based views 
Python :: how to split a dataframe into train and test 
Python :: getting-the-last-element-of-a-list 
Python :: discord.py add avatar to embed 
Python :: includes python 
Python :: python class with optional arguments 
Python :: create database tables python 
Python :: numpy variance 
Python :: how to encode a string in python 
Python :: save standard output in variable python 
Python :: python bug 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =