Black and White Crates in Siborn

I am trying to draw some black and white boxes using the Python Seaborn package. By default, the graphs use a color palette. I would like to draw them with a solid black outline. The best I can come up with is:

# figure styles
sns.set_style('white')
sns.set_context('paper', font_scale=2)
plt.figure(figsize=(3, 5))
sns.set_style('ticks', {'axes.edgecolor': '0',  
                        'xtick.color': '0',
                        'ytick.color': '0'})

ax = sns.boxplot(x="test1", y="test2", data=dataset, color='white', width=.5)
sns.despine(offset=5, trim=True)
sns.plt.show()

Which produces something like:

enter image description here

I would like the outlines of the drawer to be black without any fills or changes in the color palette.

+4
source share
1 answer

You should set edgecolorfor all the boxes and use set_colorfor the six lines (mustache and median) associated with each field:

ax = sns.boxplot(x="day", y="total_bill", data=tips, color='white', width=.5, fliersize=0)

# iterate over boxes
for i,box in enumerate(ax.artists):
    box.set_edgecolor('black')
    box.set_facecolor('white')

    # iterate over whiskers and median lines
    for j in range(6*i,6*(i+1)):
         ax.lines[j].set_color('black')

If the last cycle applies to all performers and lines, it can be reduced to:

plt.setp(ax.artists, edgecolor = 'k', facecolor='w')
plt.setp(ax.lines, color='k')

ax boxplot.

enter image description here

, .

+4

Source: https://habr.com/ru/post/1674907/


All Articles