[英]How to change colour of inner box in seaborn violinplot?
我希望將sns.violinplot()
生成的內部箱線圖的顏色更改為黑色,請參見下圖。 我試過使用補丁,但只能找到如何做小提琴圖的外邊緣而不是內框。
相關代碼:
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)
您可以通過以下方式指定小提琴圖的顏色。
import seaborn as sns
df = sns.load_dataset('iris')
sns.violinplot( x=df["species"], y=df["sepal_length"], color="skyblue")
import seaborn as sns
df = sns.load_dataset('iris')
sns.violinplot(x=df["species"], y=df["sepal_length"], color="skyblue", inner=None)
sns.boxenplot(x=df["species"], y=df["sepal_length"], color="red", width=0.05)
補丁藝術家可用於更改繪圖內元素的顏色。
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)
產量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.