Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End caps on barplot confidence intervals #606 update #898

Merged
merged 13 commits into from Apr 24, 2016

Conversation

@dcgemperline
Copy link
Contributor

dcgemperline commented Mar 31, 2016

I think this fixes the end cap addition to barplot and scatterplot confidence intervals. Let me know what you think. It should pass all the automated tests. Let me know if there is anything wrong. I've attached some images, along with the python script I used to generate them. This should show you what the different parameters look like for different capsize and conf_lw. Major thanks to jat255 who did the initial work on this. This is my very first contribution to an open source project that is not my own. Let me know if there is anything else that needs to be done as far as style and/or code cleanup.

import seaborn as sns

##LINEPLOTS

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
                   palette="YlGnBu_d", size=6, aspect=.75)
g.despine(left=True)
g.savefig("test1.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
                   palette="YlGnBu_d", size=6, aspect=.75, conf_lw=1, capsize=0.3)
g.despine(left=True)
g.savefig("test2.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
                   palette="YlGnBu_d", size=6, aspect=.75, conf_lw=4, capsize=0.3)
g.despine(left=True)
g.savefig("test2b.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
                   palette="YlGnBu_d", size=6, aspect=.75, conf_lw=1, capsize=0.1)
g.despine(left=True)
g.savefig("test3.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
                   palette="YlGnBu_d", size=6, aspect=.75, conf_lw=2, capsize=0.3)
g.despine(left=True)
g.savefig("test4.png")

##BarPlots

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
                   size=6, kind="bar", palette="muted")
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test5.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
                   size=6, kind="bar", palette="muted", conf_lw=1, capsize=0.3)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test6.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
                   size=6, kind="bar", palette="muted", conf_lw=1, capsize=0.1)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test7.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
                   size=6, kind="bar", palette="muted", conf_lw=2, capsize=0.3)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test8.png")

`

test1
test2
test2b
test3
test4
test5
test6
test7
test8

@mwaskom
Copy link
Owner

mwaskom commented Apr 6, 2016

Thanks for fixing the tests and getting this working in pointplot.

Please add some tests to cover this new behavior, though.

capsize=None,
**kws):

if conf_lw:

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

If you are testing against None, do so explicitly.

**kws):

if conf_lw:
kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw)

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

This way of doing this is confusing because conf_lw sounds like you are specifying a width value, but it's really a scaling factor. I would just set the linewidth directly using this parameter.

ax, at_group,
confint,
colors,
conf_lw=None,

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

Please change here and in the external interface to errwidth for consistency with errcolor.

ax.plot([ci_high, ci_high],
[at - capsize / 2, at + capsize / 2],
color=color, **kws)
else:

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

This else clause is duplicating code. I would restructure to write the loop logic once and handle the capsize logic inside the loop.

conf_lw=dedent("""\
conf_lw : float, optional
Thickness of lines draw for the confidence interval (and caps).
Default is 1.8.\

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

Don't specify the default value in the docstring.

capsize=dedent("""\
capsize : float, optional
Length of caps on confidence interval (drawn perpendicular to
primary line. If 0.0 (default), no caps will be drawn.

This comment has been minimized.

Copy link
@mwaskom

mwaskom Apr 6, 2016

Owner

Your'e missing a closing parens.

@mwaskom
Copy link
Owner

mwaskom commented Apr 6, 2016

I have made some comments. I would suggest writing the tests first before addressing them so that you can guard against introducing errors when fixing.

@dcgemperline
Copy link
Contributor Author

dcgemperline commented Apr 6, 2016

Thanks for the quick feedback. This is my first time really writing python, so I appreciate the code review. I will see if I can implement the tests, check them in and then work on getting the changes you suggested in as well.

@dcgemperline
Copy link
Contributor Author

dcgemperline commented Apr 7, 2016

Python script with some values adjusting the errwidth and the capsize

`import seaborn as sns

##LINEPLOTS

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75)
g.despine(left=True)
g.savefig("test1.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75, errwidth=1, capsize=0.3)
g.despine(left=True)
g.savefig("test2.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75, errwidth=4, capsize=0.3)
g.despine(left=True)
g.savefig("test2b.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75, errwidth=1, capsize=0.1)
g.despine(left=True)
g.savefig("test3.png")

g=None
sns.set(style="whitegrid")
df = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75, errwidth=2, capsize=0.3)
g.despine(left=True)
g.savefig("test4.png")

##BarPlots

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
size=6, kind="bar", palette="muted")
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test5.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
size=6, kind="bar", palette="muted", errwidth=1, capsize=0.3)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test6.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
size=6, kind="bar", palette="muted", errwidth=1, capsize=0.1)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test7.png")

g=None
sns.set(style="whitegrid")
titanic = sns.load_dataset("titanic")
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
size=6, kind="bar", palette="muted", errwidth=2, capsize=0.3)
g.despine(left=True)
g.set_ylabels("survival probability")
g.savefig("test8.png")
`

test1
test2
test2b
test3
test4
test5
test6
test7
test8

@dcgemperline
Copy link
Contributor Author

dcgemperline commented Apr 14, 2016

I know you are quite busy, but does there need to be any more work done on this for it to be integrated?

@mwaskom
Copy link
Owner

mwaskom commented Apr 14, 2016

On a very quick review the code looks clean and your example plots look very thorough, but I'm waiting to get the time to actually play with it myself for a bit before hitting merge. I'll ping you if it needs any more changes.

@mwaskom mwaskom merged commit 9fbc9f7 into mwaskom:master Apr 24, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@mwaskom
Copy link
Owner

mwaskom commented Apr 24, 2016

Thanks!

@dcgemperline
Copy link
Contributor Author

dcgemperline commented Apr 24, 2016

No problem! Thanks for letting me contribute :)

@luthramanisha
Copy link

luthramanisha commented Aug 14, 2019

In seaborn version 0.9.0, new plotting functions including relplot() are released. These still don't have attributes err_width and cap_size for end caps in type line plots with confidence intervals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.