End caps on barplot confidence intervals #606 update #898

Merged
merged 13 commits into from Apr 24, 2016

Conversation

Projects
None yet
2 participants
@dcgemperline
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

This comment has been minimized.

Show comment
Hide comment
@mwaskom

mwaskom Apr 6, 2016

Owner

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

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

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.

seaborn/categorical.py
+ capsize=None,
+ **kws):
+
+ if conf_lw:

This comment has been minimized.

@mwaskom

mwaskom Apr 6, 2016

Owner

If you are testing against None, do so explicitly.

@mwaskom

mwaskom Apr 6, 2016

Owner

If you are testing against None, do so explicitly.

seaborn/categorical.py
+ **kws):
+
+ if conf_lw:
+ kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw)

This comment has been minimized.

@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.

@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.

seaborn/categorical.py
+ ax, at_group,
+ confint,
+ colors,
+ conf_lw=None,

This comment has been minimized.

@mwaskom

mwaskom Apr 6, 2016

Owner

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

@mwaskom

mwaskom Apr 6, 2016

Owner

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

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

This comment has been minimized.

@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.

@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.

seaborn/categorical.py
+ 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.

@mwaskom

mwaskom Apr 6, 2016

Owner

Don't specify the default value in the docstring.

@mwaskom

mwaskom Apr 6, 2016

Owner

Don't specify the default value in the docstring.

seaborn/categorical.py
+ 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.

@mwaskom

mwaskom Apr 6, 2016

Owner

Your'e missing a closing parens.

@mwaskom

mwaskom Apr 6, 2016

Owner

Your'e missing a closing parens.

@mwaskom

This comment has been minimized.

Show comment
Hide comment
@mwaskom

mwaskom Apr 6, 2016

Owner

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.

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

This comment has been minimized.

Show comment
Hide comment
@dcgemperline

dcgemperline Apr 6, 2016

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@dcgemperline

dcgemperline Apr 7, 2016

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@dcgemperline

dcgemperline Apr 14, 2016

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@mwaskom

mwaskom Apr 14, 2016

Owner

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.

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

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@mwaskom

This comment has been minimized.

Show comment
Hide comment
@mwaskom

mwaskom Apr 24, 2016

Owner

Thanks!

Owner

mwaskom commented Apr 24, 2016

Thanks!

@dcgemperline

This comment has been minimized.

Show comment
Hide comment
@dcgemperline

dcgemperline Apr 24, 2016

Contributor

No problem! Thanks for letting me contribute :)

Contributor

dcgemperline commented Apr 24, 2016

No problem! Thanks for letting me contribute :)

@pyup-bot pyup-bot referenced this pull request in mayou36/raredecay May 18, 2017

Closed

Pin seaborn to latest version 0.7.1 #10

@pyup-bot pyup-bot referenced this pull request in mozilla/emr-bootstrap-spark Jul 9, 2017

Closed

Update seaborn to 0.8 #98

@pyup-bot pyup-bot referenced this pull request in mozilla/emr-bootstrap-spark Sep 3, 2017

Open

Update seaborn to 0.8.1 #119

@pyup-bot pyup-bot referenced this pull request in tnir/pandas Feb 2, 2018

Open

Pin seaborn to latest version 0.8.1 #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment