Seaborn regplot中点和线的不同颜色 [英] Different colors for points and line in Seaborn regplot
本文介绍了Seaborn regplot中点和线的不同颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
All examples listed in Seaborn's regplot
documentation show the same color for dots and the regression line. Changing the color
argument changes both. How can one set a different color for the points as the line?
解决方案
You are right in that the color
argument changes all the plot elements. However, if you read the last bit of the relevant sentence in the documentation:
color : matplotlib color
Color to apply to all plot elements; will be superseded by colors passed in
scatter_kws
orline_kws
.
Therefore, using scatter_kws
or line_kws
we can change the color of them individually. Taking the first example given in the documentation:
import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.regplot(x="total_bill", y="tip", data=tips,
scatter_kws={"color": "black"}, line_kws={"color": "red"})
plt.show()
Gives:
这篇关于Seaborn regplot中点和线的不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文