简体   繁体   English

seaborn\\matplotlib\\pandas 绘图未显示 ylabel

[英]seaborn\matplotlib\pandas plot not showing ylabel

I'm trying to create a violin plot for some data, but for some reason my ylabel won't change.我正在尝试为某些数据创建一个小提琴图,但由于某种原因,我的 ylabel 不会改变。

fig, ax = plt.subplots(figsize=(10, 5))
ax.set_title('Violin plots for fat content per lab', size=18, weight='bold')
ax.set_ylabel('Fat content (%)')

sns.violinplot(data=df_eggs, x='Lab', y='Fat_Content', ax=ax);

I'm using Jupyter Notebook and I imported pandas, seaborn and matplotlib beforehand.我正在使用 Jupyter Notebook 并事先导入了 Pandas、seaborn 和 matplotlib。 Here is the result .结果如下

The commentor is right.评论家说得对。 Just change the order of things like this:只需改变这样的事情的顺序:

fig, ax = plt.subplots(figsize=(10, 5))
ax.set_title('Violin plots for fat content per lab', size=18, weight='bold')
sns.violinplot(data=df_eggs, x='Lab', y='Fat_Content', ax=ax)
ax.set_ylabel('Fat content (%)')

When you put the ax.set_ylabel before the sns.violinplot , the label you set with the ax.set_ylabel is being overwritten with the y label written by the sns.violinplot .当你把ax.set_ylabel的前sns.violinplot ,你设定的标签ax.set_ylabel被覆盖由写在y标签sns.violinplot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM