From 7603d9c0e1929bf8af673fbae1a0df34f63d8023 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Wed, 30 Mar 2016 18:06:03 -0500 Subject: [PATCH 01/12] Added jat255's cchanges with some edits to get tests passing stil some errors --- seaborn/categorical.py | 84 +++++++++++++++++++++++++------ seaborn/tests/test_categorical.py | 4 +- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 49b56729aa..bb7d9ceaec 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1498,24 +1498,43 @@ def estimate_statistic(self, estimator, ci, n_boot): self.value_label = "{}({})".format(estimator.__name__, self.value_label) - def draw_confints(self, ax, at_group, confint, colors, **kws): + def draw_confints(self, + ax, at_group, + confint, + colors, + conf_lw=1, + capsize=0, + **kws): - kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) + kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) + kws.pop('lw') for at, (ci_low, ci_high), color in zip(at_group, confint, colors): if self.orient == "v": - ax.plot([at, at], [ci_low, ci_high], color=color, **kws) + ax.plot([at, at], [ci_low, ci_high], color=color, + lw=conf_lw, **kws) + ax.plot([at - capsize / 2, at + capsize / 2], + [ci_low, ci_low], color=color, lw=conf_lw, **kws) + ax.plot([at - capsize / 2, at + capsize / 2], + [ci_high, ci_high], color=color, lw=conf_lw, **kws) else: - ax.plot([ci_low, ci_high], [at, at], color=color, **kws) - + ax.plot([ci_low, ci_high], [at, at], color=color, + lw=conf_lw, **kws) + ax.plot([ci_low, ci_low], + [at - capsize /2, at + capsize /2], + color=color, lw=conf_lw, **kws) + ax.plot([ci_high, ci_high], + [at - capsize /2, at + capsize /2], + color=color, lw=conf_lw, **kws) class _BarPlotter(_CategoricalStatPlotter): """Show point estimates and confidence intervals with bars.""" def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, - orient, color, palette, saturation, errcolor): + orient, color, palette, saturation, errcolor, conf_lw, + capsize): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, order, hue_order, units) @@ -1523,6 +1542,8 @@ def __init__(self, x, y, hue, data, order, hue_order, self.estimate_statistic(estimator, ci, n_boot) self.errcolor = errcolor + self.conf_lw = conf_lw + self.capsize = capsize def draw_bars(self, ax, kws): """Draw the bars onto `ax`.""" @@ -1538,7 +1559,12 @@ def draw_bars(self, ax, kws): # Draw the confidence intervals errcolors = [self.errcolor] * len(barpos) - self.draw_confints(ax, barpos, self.confint, errcolors) + self.draw_confints(ax, + barpos, + self.confint, + errcolors, + self.conf_lw, + self.capsize) else: @@ -1554,7 +1580,12 @@ def draw_bars(self, ax, kws): if self.confint.size: confint = self.confint[:, j] errcolors = [self.errcolor] * len(offpos) - self.draw_confints(ax, offpos, confint, errcolors) + self.draw_confints(ax, + offpos, + confint, + errcolors, + self.conf_lw, + self.capsize) def plot(self, ax, bar_kws): """Make the plot.""" @@ -1569,7 +1600,7 @@ class _PointPlotter(_CategoricalStatPlotter): def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, - orient, color, palette): + orient, color, palette, conf_lw, capsize): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, order, hue_order, units) @@ -1602,6 +1633,8 @@ def __init__(self, x, y, hue, data, order, hue_order, self.dodge = dodge self.join = join self.scale = scale + self.conf_lw = conf_lw + self.capsize = capsize @property def hue_offsets(self): @@ -1634,7 +1667,8 @@ def draw_points(self, ax): color=color, ls=ls, lw=lw) # Draw the confidence intervals - self.draw_confints(ax, pointpos, self.confint, self.colors, lw=lw) + self.draw_confints(ax, pointpos, self.confint, self.colors, + self.conf_lw, self.capsize, lw=lw) # Draw the estimate points marker = self.markers[0] @@ -1675,6 +1709,7 @@ def draw_points(self, ax): confint = self.confint[:, j] errcolors = [self.colors[j]] * len(offpos) self.draw_confints(ax, offpos, confint, errcolors, + self.conf_lw, self.capsize, zorder=z, lw=lw) # Draw the estimate points @@ -2025,6 +2060,17 @@ def plot(self, ax, boxplot_kws): ``1`` if you want the plot colors to perfectly match the input color spec.\ """), + 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. Typical values are + between 0.03 and 0.1.\ + """), + conf_lw = dedent("""\ + conf_lw : float, optional + Thickness of lines draw for the confidence interval (and caps). + Default is 1.8.\ + """), width=dedent("""\ width : float, optional Width of a full element when not using hue nesting, or width of all the @@ -2074,6 +2120,9 @@ def plot(self, ax, boxplot_kws): lvplot=dedent("""\ lvplot : An extension of the boxplot for long-tailed and large data sets. """), + + + ) _categorical_docs.update(_facet_docs) @@ -2831,7 +2880,7 @@ def swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=.75, - errcolor=".26", ax=None, **kwargs): + errcolor=".26", conf_lw=1.8, capsize=0, ax=None, **kwargs): # Handle some deprecated arguments if "hline" in kwargs: @@ -2850,7 +2899,7 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, plotter = _BarPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, - errcolor) + errcolor, conf_lw, capsize) if ax is None: ax = plt.gca() @@ -2894,6 +2943,8 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, errcolor : matplotlib color Color for the lines that represent the confidence interval. {ax_in} + {conf_lw} + {capsize} kwargs : key, value mappings Other keyword arguments are passed through to ``plt.bar`` at draw time. @@ -2989,7 +3040,8 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, markers="o", linestyles="-", dodge=False, join=True, scale=1, - orient=None, color=None, palette=None, ax=None, **kwargs): + orient=None, color=None, palette=None, ax=None, conf_lw=1.8, + capsize=0, **kwargs): # Handle some deprecated arguments if "hline" in kwargs: @@ -3008,7 +3060,7 @@ def pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, plotter = _PointPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, - orient, color, palette) + orient, color, palette, conf_lw, capsize) if ax is None: ax = plt.gca() @@ -3187,12 +3239,12 @@ def countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, elif x is not None and y is not None: raise TypeError("Cannot pass values for both `x` and `y`") else: - raise TypeError("Must pass valus for either `x` or `y`") + raise TypeError("Must pass values for either `x` or `y`") plotter = _BarPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, - errcolor) + errcolor, conf_lw=1, capsize=0) plotter.value_label = "count" diff --git a/seaborn/tests/test_categorical.py b/seaborn/tests/test_categorical.py index 3c0f921b90..27c41389c0 100644 --- a/seaborn/tests/test_categorical.py +++ b/seaborn/tests/test_categorical.py @@ -1749,7 +1749,7 @@ class TestBarPlotter(CategoricalFixture): estimator=np.mean, ci=95, n_boot=100, units=None, order=None, hue_order=None, orient=None, color=None, palette=None, - saturation=.75, errcolor=".26") + saturation=.75, errcolor=".26", conf_lw=1.8, capsize=0) def test_nested_width(self): @@ -1974,7 +1974,7 @@ class TestPointPlotter(CategoricalFixture): order=None, hue_order=None, markers="o", linestyles="-", dodge=0, join=True, scale=1, - orient=None, color=None, palette=None) + orient=None, color=None, palette=None, conf_lw=1, capsize=0) def test_different_defualt_colors(self): From fef4fcd3cb3595b5bee0f84279ac7e4d685588ed Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Wed, 30 Mar 2016 23:56:10 -0500 Subject: [PATCH 02/12] Added Error Bar Cap Functionality All Tests Passing --- seaborn/categorical.py | 78 +++++++++++++++++-------------- seaborn/tests/test_categorical.py | 4 +- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index bb7d9ceaec..33e65b9137 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1502,39 +1502,49 @@ def draw_confints(self, ax, at_group, confint, colors, - conf_lw=1, - capsize=0, + conf_lw=None, + capsize=None, **kws): - kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) - kws.pop('lw') - - for at, (ci_low, ci_high), color in zip(at_group, - confint, - colors): - if self.orient == "v": - ax.plot([at, at], [ci_low, ci_high], color=color, - lw=conf_lw, **kws) - ax.plot([at - capsize / 2, at + capsize / 2], - [ci_low, ci_low], color=color, lw=conf_lw, **kws) - ax.plot([at - capsize / 2, at + capsize / 2], - [ci_high, ci_high], color=color, lw=conf_lw, **kws) - else: - ax.plot([ci_low, ci_high], [at, at], color=color, - lw=conf_lw, **kws) - ax.plot([ci_low, ci_low], - [at - capsize /2, at + capsize /2], - color=color, lw=conf_lw, **kws) - ax.plot([ci_high, ci_high], - [at - capsize /2, at + capsize /2], - color=color, lw=conf_lw, **kws) + if conf_lw: + kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) + kws.pop("lw") + else: + kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) + + if capsize: + for at, (ci_low, ci_high), color in zip(at_group, + confint, + colors): + if self.orient == "v": + ax.plot([at, at], [ci_low, ci_high], color=color, **kws) + ax.plot([at - capsize / 2, at + capsize / 2], + [ci_low, ci_low], color=color, **kws) + ax.plot([at - capsize / 2, at + capsize / 2], + [ci_high, ci_high], color=color, **kws) + else: + ax.plot([ci_low, ci_high], [at, at], color=color, **kws) + ax.plot([ci_low, ci_low], + [at - capsize /2, at + capsize /2], + color=color, **kws) + ax.plot([ci_high, ci_high], + [at - capsize /2, at + capsize /2], + color=color, **kws) + else: + for at, (ci_low, ci_high), color in zip(at_group, + confint, + colors): + if self.orient == "v": + ax.plot([at, at], [ci_low, ci_high], color=color, **kws) + else: + ax.plot([ci_low, ci_high], [at, at], color=color, **kws) class _BarPlotter(_CategoricalStatPlotter): """Show point estimates and confidence intervals with bars.""" def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, - orient, color, palette, saturation, errcolor, conf_lw, - capsize): + orient, color, palette, saturation, errcolor, conf_lw=None, + capsize=None): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, order, hue_order, units) @@ -1587,6 +1597,7 @@ def draw_bars(self, ax, kws): self.conf_lw, self.capsize) + def plot(self, ax, bar_kws): """Make the plot.""" self.draw_bars(ax, bar_kws) @@ -1600,7 +1611,7 @@ class _PointPlotter(_CategoricalStatPlotter): def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, - orient, color, palette, conf_lw, capsize): + orient, color, palette, conf_lw=None, capsize=None): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, order, hue_order, units) @@ -1668,8 +1679,7 @@ def draw_points(self, ax): # Draw the confidence intervals self.draw_confints(ax, pointpos, self.confint, self.colors, - self.conf_lw, self.capsize, lw=lw) - + self.conf_lw, self.capsize) # Draw the estimate points marker = self.markers[0] if self.orient == "h": @@ -1710,7 +1720,7 @@ def draw_points(self, ax): errcolors = [self.colors[j]] * len(offpos) self.draw_confints(ax, offpos, confint, errcolors, self.conf_lw, self.capsize, - zorder=z, lw=lw) + zorder=z) # Draw the estimate points marker = self.markers[j] @@ -2880,7 +2890,7 @@ def swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=.75, - errcolor=".26", conf_lw=1.8, capsize=0, ax=None, **kwargs): + errcolor=".26", conf_lw=None, capsize=None, ax=None, **kwargs): # Handle some deprecated arguments if "hline" in kwargs: @@ -3040,8 +3050,8 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, markers="o", linestyles="-", dodge=False, join=True, scale=1, - orient=None, color=None, palette=None, ax=None, conf_lw=1.8, - capsize=0, **kwargs): + orient=None, color=None, palette=None, ax=None, conf_lw=None, + capsize=None, **kwargs): # Handle some deprecated arguments if "hline" in kwargs: @@ -3244,7 +3254,7 @@ def countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, plotter = _BarPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, - errcolor, conf_lw=1, capsize=0) + errcolor) plotter.value_label = "count" diff --git a/seaborn/tests/test_categorical.py b/seaborn/tests/test_categorical.py index 27c41389c0..3c0f921b90 100644 --- a/seaborn/tests/test_categorical.py +++ b/seaborn/tests/test_categorical.py @@ -1749,7 +1749,7 @@ class TestBarPlotter(CategoricalFixture): estimator=np.mean, ci=95, n_boot=100, units=None, order=None, hue_order=None, orient=None, color=None, palette=None, - saturation=.75, errcolor=".26", conf_lw=1.8, capsize=0) + saturation=.75, errcolor=".26") def test_nested_width(self): @@ -1974,7 +1974,7 @@ class TestPointPlotter(CategoricalFixture): order=None, hue_order=None, markers="o", linestyles="-", dodge=0, join=True, scale=1, - orient=None, color=None, palette=None, conf_lw=1, capsize=0) + orient=None, color=None, palette=None) def test_different_defualt_colors(self): From 0676d1f5948dee4825caf29297dbcfdb08399af5 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 31 Mar 2016 00:40:23 -0500 Subject: [PATCH 03/12] Final Changes to Error Bar Caps --- seaborn/categorical.py | 1 - 1 file changed, 1 deletion(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 33e65b9137..415cb2c864 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1508,7 +1508,6 @@ def draw_confints(self, if conf_lw: kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) - kws.pop("lw") else: kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) From 2715aa066c13c1369f72b8bf7021822f4eeb940f Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 31 Mar 2016 01:22:06 -0500 Subject: [PATCH 04/12] formatting changes --- seaborn/categorical.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 415cb2c864..84e0aa7a0f 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1524,22 +1524,22 @@ def draw_confints(self, else: ax.plot([ci_low, ci_high], [at, at], color=color, **kws) ax.plot([ci_low, ci_low], - [at - capsize /2, at + capsize /2], + [at - capsize / 2, at + capsize / 2], color=color, **kws) ax.plot([ci_high, ci_high], - [at - capsize /2, at + capsize /2], + [at - capsize / 2, at + capsize / 2], color=color, **kws) else: - for at, (ci_low, ci_high), color in zip(at_group, - confint, - colors): + for at, (ci_low, ci_high), color in zip(at_group, confint, colors): if self.orient == "v": ax.plot([at, at], [ci_low, ci_high], color=color, **kws) else: ax.plot([ci_low, ci_high], [at, at], color=color, **kws) + class _BarPlotter(_CategoricalStatPlotter): """Show point estimates and confidence intervals with bars.""" + def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, conf_lw=None, @@ -1596,7 +1596,6 @@ def draw_bars(self, ax, kws): self.conf_lw, self.capsize) - def plot(self, ax, bar_kws): """Make the plot.""" self.draw_bars(ax, bar_kws) @@ -2071,11 +2070,11 @@ def plot(self, ax, boxplot_kws): """), 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. Typical values are - between 0.03 and 0.1.\ + Length of caps on confidence interval (drawn perpendicular to + primary line. If 0.0 (default), no caps will be drawn. + Typical values are between 0.03 and 0.1.\ """), - conf_lw = dedent("""\ + conf_lw=dedent("""\ conf_lw : float, optional Thickness of lines draw for the confidence interval (and caps). Default is 1.8.\ From ace49a906d6ff4872f7f73bd20fbe3746131c719 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:10:28 -0500 Subject: [PATCH 05/12] Added Tests for errobar caps --- seaborn/tests/test_categorical.py | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/seaborn/tests/test_categorical.py b/seaborn/tests/test_categorical.py index 3c0f921b90..866b0a1d13 100644 --- a/seaborn/tests/test_categorical.py +++ b/seaborn/tests/test_categorical.py @@ -650,6 +650,32 @@ def test_draw_cis(self): plt.close("all") + # Test vertical CIs with endcaps + p.orient = "v" + + f, ax = plt.subplots() + p.draw_confints(ax, at_group, confints, colors, capsize=0.3) + capline = ax.lines[len(ax.lines) - 1] + caplinestart = capline.get_xdata()[0] + caplineend = capline.get_xdata()[1] + caplinelength = abs(caplineend - caplinestart) + nt.assert_almost_equal(caplinelength, 0.3) + nt.assert_equal(len(ax.lines), 6) + + plt.close("all") + + # Test horizontal CIs with endcaps + p.orient = "h" + + f, ax = plt.subplots() + p.draw_confints(ax, at_group, confints, colors, capsize=0.3) + capline = ax.lines[len(ax.lines) - 1] + caplinestart = capline.get_ydata()[0] + caplineend = capline.get_ydata()[1] + caplinelength = abs(caplineend - caplinestart) + nt.assert_almost_equal(caplinelength, 0.3) + nt.assert_equal(len(ax.lines), 6) + # Test extra keyword arguments f, ax = plt.subplots() p.draw_confints(ax, at_group, confints, colors, lw=4) @@ -658,6 +684,15 @@ def test_draw_cis(self): plt.close("all") + # Test conf_lw is set appropriately + f, ax = plt.subplots() + p.draw_confints(ax, at_group, confints, colors, conf_lw=2) + capline = ax.lines[len(ax.lines)-1] + nt.assert_equal(capline._linewidth, 2) + nt.assert_equal(len(ax.lines), 2) + + plt.close("all") + class TestBoxPlotter(CategoricalFixture): @@ -1966,7 +2001,6 @@ def test_simple_barplots(self): nt.assert_equal(ax.get_ylabel(), "g") plt.close("all") - class TestPointPlotter(CategoricalFixture): default_kws = dict(x=None, y=None, hue=None, data=None, From 752a59e2c04494ec19e5cfb0254ab319aae73358 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:21:52 -0500 Subject: [PATCH 06/12] Explicitly test against None --- seaborn/categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 84e0aa7a0f..100d7baf20 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1506,12 +1506,12 @@ def draw_confints(self, capsize=None, **kws): - if conf_lw: + if conf_lw is not None: kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) else: kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) - if capsize: + if capsize is not None: for at, (ci_low, ci_high), color in zip(at_group, confint, colors): From a030a0fda03a74bac26f30ead01b0c7ecb0f6ce5 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:24:11 -0500 Subject: [PATCH 07/12] Change conf_lw to errwidth --- seaborn/categorical.py | 36 +++++++++++++++---------------- seaborn/tests/test_categorical.py | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 100d7baf20..f41f5fbf2a 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1502,12 +1502,12 @@ def draw_confints(self, ax, at_group, confint, colors, - conf_lw=None, + errwidth=None, capsize=None, **kws): - if conf_lw is not None: - kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * conf_lw) + if errwidth is not None: + kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * errwidth) else: kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) @@ -1542,7 +1542,7 @@ class _BarPlotter(_CategoricalStatPlotter): def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, - orient, color, palette, saturation, errcolor, conf_lw=None, + orient, color, palette, saturation, errcolor, errwidth=None, capsize=None): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, @@ -1551,7 +1551,7 @@ def __init__(self, x, y, hue, data, order, hue_order, self.estimate_statistic(estimator, ci, n_boot) self.errcolor = errcolor - self.conf_lw = conf_lw + self.errwidth = errwidth self.capsize = capsize def draw_bars(self, ax, kws): @@ -1572,7 +1572,7 @@ def draw_bars(self, ax, kws): barpos, self.confint, errcolors, - self.conf_lw, + self.errwidth, self.capsize) else: @@ -1593,7 +1593,7 @@ def draw_bars(self, ax, kws): offpos, confint, errcolors, - self.conf_lw, + self.errwidth, self.capsize) def plot(self, ax, bar_kws): @@ -1609,7 +1609,7 @@ class _PointPlotter(_CategoricalStatPlotter): def __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, - orient, color, palette, conf_lw=None, capsize=None): + orient, color, palette, errwidth=None, capsize=None): """Initialize the plotter.""" self.establish_variables(x, y, hue, data, orient, order, hue_order, units) @@ -1642,7 +1642,7 @@ def __init__(self, x, y, hue, data, order, hue_order, self.dodge = dodge self.join = join self.scale = scale - self.conf_lw = conf_lw + self.errwidth = errwidth self.capsize = capsize @property @@ -1677,7 +1677,7 @@ def draw_points(self, ax): # Draw the confidence intervals self.draw_confints(ax, pointpos, self.confint, self.colors, - self.conf_lw, self.capsize) + self.errwidth, self.capsize) # Draw the estimate points marker = self.markers[0] if self.orient == "h": @@ -1717,7 +1717,7 @@ def draw_points(self, ax): confint = self.confint[:, j] errcolors = [self.colors[j]] * len(offpos) self.draw_confints(ax, offpos, confint, errcolors, - self.conf_lw, self.capsize, + self.errwidth, self.capsize, zorder=z) # Draw the estimate points @@ -2074,8 +2074,8 @@ def plot(self, ax, boxplot_kws): primary line. If 0.0 (default), no caps will be drawn. Typical values are between 0.03 and 0.1.\ """), - conf_lw=dedent("""\ - conf_lw : float, optional + errwidth=dedent("""\ + errwidth : float, optional Thickness of lines draw for the confidence interval (and caps). Default is 1.8.\ """), @@ -2888,7 +2888,7 @@ def swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=.75, - errcolor=".26", conf_lw=None, capsize=None, ax=None, **kwargs): + errcolor=".26", errwidth=None, capsize=None, ax=None, **kwargs): # Handle some deprecated arguments if "hline" in kwargs: @@ -2907,7 +2907,7 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, plotter = _BarPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, - errcolor, conf_lw, capsize) + errcolor, errwidth, capsize) if ax is None: ax = plt.gca() @@ -2951,7 +2951,7 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, errcolor : matplotlib color Color for the lines that represent the confidence interval. {ax_in} - {conf_lw} + {errwidth} {capsize} kwargs : key, value mappings Other keyword arguments are passed through to ``plt.bar`` at draw @@ -3048,7 +3048,7 @@ def barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, def pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=np.mean, ci=95, n_boot=1000, units=None, markers="o", linestyles="-", dodge=False, join=True, scale=1, - orient=None, color=None, palette=None, ax=None, conf_lw=None, + orient=None, color=None, palette=None, ax=None, errwidth=None, capsize=None, **kwargs): # Handle some deprecated arguments @@ -3068,7 +3068,7 @@ def pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, plotter = _PointPlotter(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, - orient, color, palette, conf_lw, capsize) + orient, color, palette, errwidth, capsize) if ax is None: ax = plt.gca() diff --git a/seaborn/tests/test_categorical.py b/seaborn/tests/test_categorical.py index 866b0a1d13..d24efc474d 100644 --- a/seaborn/tests/test_categorical.py +++ b/seaborn/tests/test_categorical.py @@ -684,9 +684,9 @@ def test_draw_cis(self): plt.close("all") - # Test conf_lw is set appropriately + # Test errwidth is set appropriately f, ax = plt.subplots() - p.draw_confints(ax, at_group, confints, colors, conf_lw=2) + p.draw_confints(ax, at_group, confints, colors, errwidth=2) capline = ax.lines[len(ax.lines)-1] nt.assert_equal(capline._linewidth, 2) nt.assert_equal(len(ax.lines), 2) From 5e3e0b1ca8bd80a231dd50283c8a85b28675bb4a Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:25:34 -0500 Subject: [PATCH 08/12] Fix'd docstring so default value isn't specified --- seaborn/categorical.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index f41f5fbf2a..19e8f34435 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -2076,8 +2076,7 @@ def plot(self, ax, boxplot_kws): """), errwidth=dedent("""\ errwidth : float, optional - Thickness of lines draw for the confidence interval (and caps). - Default is 1.8.\ + Thickness of lines drawn for the confidence interval (and caps).\ """), width=dedent("""\ width : float, optional From a5e71f7c24db6e8de8d1569d5f18573e0efdcc23 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:26:31 -0500 Subject: [PATCH 09/12] Fix'd docstring for capsize --- seaborn/categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 19e8f34435..13ab4bd38c 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -2071,7 +2071,7 @@ def plot(self, ax, boxplot_kws): 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. + primary line). If unspecified, no caps will be drawn. Typical values are between 0.03 and 0.1.\ """), errwidth=dedent("""\ From c60e94b4d11dcb7327cd0980d19e017a8c850908 Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:31:38 -0500 Subject: [PATCH 10/12] Set errwidth directly instead of scaling --- seaborn/categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 13ab4bd38c..7428425499 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1507,9 +1507,9 @@ def draw_confints(self, **kws): if errwidth is not None: - kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * errwidth) + kws.setdefault("lw", errwidth) else: - kws.setdefault("lw", mpl.rcParams["lines.linewidth"] * 1.8) + kws.setdefault("lw", 1.8) if capsize is not None: for at, (ci_low, ci_high), color in zip(at_group, From 07302f4f1095f08ebf2d9a60dd2f5a959f54905d Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:34:43 -0500 Subject: [PATCH 11/12] restructured for loop to handle capsize logic inside loop, and write loop only once --- seaborn/categorical.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 7428425499..a2a273f81b 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -1511,30 +1511,25 @@ def draw_confints(self, else: kws.setdefault("lw", 1.8) - if capsize is not None: - for at, (ci_low, ci_high), color in zip(at_group, - confint, - colors): - if self.orient == "v": - ax.plot([at, at], [ci_low, ci_high], color=color, **kws) + for at, (ci_low, ci_high), color in zip(at_group, + confint, + colors): + if self.orient == "v": + ax.plot([at, at], [ci_low, ci_high], color=color, **kws) + if capsize is not None: ax.plot([at - capsize / 2, at + capsize / 2], [ci_low, ci_low], color=color, **kws) ax.plot([at - capsize / 2, at + capsize / 2], [ci_high, ci_high], color=color, **kws) - else: - ax.plot([ci_low, ci_high], [at, at], color=color, **kws) + else: + ax.plot([ci_low, ci_high], [at, at], color=color, **kws) + if capsize is not None: ax.plot([ci_low, ci_low], [at - capsize / 2, at + capsize / 2], color=color, **kws) ax.plot([ci_high, ci_high], [at - capsize / 2, at + capsize / 2], color=color, **kws) - else: - for at, (ci_low, ci_high), color in zip(at_group, confint, colors): - if self.orient == "v": - ax.plot([at, at], [ci_low, ci_high], color=color, **kws) - else: - ax.plot([ci_low, ci_high], [at, at], color=color, **kws) class _BarPlotter(_CategoricalStatPlotter): From 9fbc9f78b90a52704118980807462296cd8021ad Mon Sep 17 00:00:00 2001 From: "David C. Gemperline" Date: Thu, 7 Apr 2016 13:42:51 -0500 Subject: [PATCH 12/12] Formatting issues fixed --- seaborn/tests/test_categorical.py | 1 + 1 file changed, 1 insertion(+) diff --git a/seaborn/tests/test_categorical.py b/seaborn/tests/test_categorical.py index d24efc474d..be54281a5d 100644 --- a/seaborn/tests/test_categorical.py +++ b/seaborn/tests/test_categorical.py @@ -2001,6 +2001,7 @@ def test_simple_barplots(self): nt.assert_equal(ax.get_ylabel(), "g") plt.close("all") + class TestPointPlotter(CategoricalFixture): default_kws = dict(x=None, y=None, hue=None, data=None,