matplotlib - How to change the line color in seaborn linear regression jointplot -
as described in seaborn api following code produce linear regression plot.
import numpy np, pandas pd; np.random.seed(0) import seaborn sns; sns.set(style="white", color_codes=true) tips = sns.load_dataset("tips") g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='reg') sns.plt.show()
however, lot of data points regression line not visible anymore. how can change color? not find builtin seaborn command.
in case line in background (i.e. behind dots), ask how bring front.
there couple approaches, mwaskom tactfully pointed out. can pass arguments joint plot, setting color
there affects whole scatterplot:
import numpy np, pandas pd; np.random.seed(0) import seaborn sns#; sns.set(style="white", color_codes=true) tips = sns.load_dataset("tips") g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='reg', joint_kws={'color':'green'}) # scatter , regression green
or pass dictionary of line-plotting keywords through dictionary of scatterplot keywords. read seaborn/linearmodels.py
figure out this, entertaining , informative in itself. dict in dict:
g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='reg', joint_kws={'line_kws':{'color':'cyan'}}) # regression cyan
or can access line after it's been plotted , change directly. depends on regression line being first line plotted, break seaborn updates. it's aesthetically/pedagogically different, don't recolor uncertainty spread. way familiar jointgrid
object , how else might interact it. (and maybe there properties can't set function call arguments, although can't think of any.)
g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='reg') regline = g.ax_joint.get_lines()[0] regline.set_color('red') regline.set_zorder('5')
Comments
Post a Comment