I am looking to change the colour of the inner box plot generated by sns.violinplot()
to black, see picture below. I've tried using patch but can only find how to do the outer edge of the violin plot and not the inner box.
Relevant code:
def poros_voilin(data):
fig, ax = plt.subplots()
sns.set_style(rc={'patch'})
ax.axhline(0.84, xmin=0.26, xmax=0.94, color='k')
ax.annotate(xy=(0.795, 0.63), xycoords='axes fraction', xytext=(0.795, 0.63), textcoords='axes fraction',
s='SGL 25 BA')
ax.axhline(0.78, xmin=0.36, xmax=0.985, color='k')
ax.annotate(xy=(0.69, 0.535), xycoords='axes fraction', xytext=(0.69, 0.535), textcoords='axes fraction',
s='Toaray 060, 090, 120')
ax.axhline(0.63, xmin=0.485, xmax=0.755, color='k')
ax.annotate(xy=(0.54, 0.29), xycoords='axes fraction', xytext=(0.54, 0.29), textcoords='axes fraction',
s='ELAT LT 1400W')
vplot = sns.violinplot(y=data['poros'].astype(float), ax=ax)
plt.show()
if __name__ == '__main__':
data = load_data()
poros_violin(data)
Patch artist can be used to change the colour of elements inside of a plot.
def poros_voilin(data):
fig, ax = plt.subplots()
# ax.axhline(0.84, xmin=0.26, xmax=0.98, color='k')
ax.axhline(0.84, color='k', linestyle='--', linewidth=1)
ax.annotate(xy=(0.98, 0.63), xycoords='axes fraction', xytext=(0.98, 0.63), textcoords='axes fraction',
s='SGL 25 BA', ha='right')
# ax.axhline(0.78, xmin=0.36, xmax=0.98, color='k')
ax.axhline(0.78, color='k', linestyle='-.', linewidth=1)
ax.annotate(xy=(0.98, 0.535), xycoords='axes fraction', xytext=(0.98, 0.535), textcoords='axes fraction',
s='Toray 060, 090, 120', ha='right')
# ax.axhline(0.63, xmin=0.485, xmax=0.98, color='k')
ax.axhline(0.63, color='k', linestyle=':', linewidth=1.5)
ax.annotate(xy=(0.98, 0.29), xycoords='axes fraction', xytext=(0.98, 0.29), textcoords='axes fraction',
s='ELAT LT 1400W', ha='right')
vplot = sns.violinplot(y=data['poros'].astype(float), ax=ax)
ax.get_children()[5].set_color('k') # <------------- changes the colour of the sticks
ax.get_children()[6].set_color('k') # <------------- changes the colour of the box
# sns.boxenplot(y=data['poros'].astype(float), ax=ax)
plt.show()
if __name__ == '__main__':
data = load_data()
poros_violin(data)
yields