From 5a22790f40d736dfd4abddeb0a938e7e4d29a810 Mon Sep 17 00:00:00 2001 From: Taylor Wong Date: Fri, 23 Oct 2015 22:47:27 -0700 Subject: [PATCH 1/3] implement boxplot visualization --- datascience/tables.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/datascience/tables.py b/datascience/tables.py index f591ddf7e..3b67296c4 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1621,6 +1621,33 @@ def hist(self, overlay=False, bins=None, counts=None, **vargs): vargs['weights'] = columns[label] axis.hist(values, color=color, **vargs) + def boxplot(self, **vargs): + """Plots a boxplot for the table. + + Kwargs: + vargs: Additional arguments that get passed into `plt.boxplot`. + See http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.boxplot + for additional arguments that can be passed into vargs. These include: + + Returns: + None + + Raises: + ValueError: The Table contains columns with non-numerical values. + + """ + # Check for non-numerical values and raise a ValueError if any found + for col in self: + if any(isinstance(cell, np.flexible) for cell in self[col]): + raise ValueError("The column '{0}' contains non-numerical " + "values. A histogram cannot be drawn for this table." + .format(col)) + + columns = self._columns.copy() + vargs['labels'] = columns.keys() + values = list(columns.values()) + plt.boxplot(values, **vargs) + def points(self, column__lat, column__long, labels=None, colors=None, **kwargs) : latitudes = self._get_column(column__lat) longitudes = self._get_column(column__long) From 0cf41c05ae01336902c426d9868c9b16a1dc7a22 Mon Sep 17 00:00:00 2001 From: Taylor Wong Date: Mon, 26 Oct 2015 02:30:01 -0700 Subject: [PATCH 2/3] add documentation for Table boxplot method --- datascience/tables.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/datascience/tables.py b/datascience/tables.py index 3b67296c4..f6599ad35 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1627,7 +1627,8 @@ def boxplot(self, **vargs): Kwargs: vargs: Additional arguments that get passed into `plt.boxplot`. See http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.boxplot - for additional arguments that can be passed into vargs. These include: + for additional arguments that can be passed into vargs. These include + `vert` and `showmeans`. Returns: None @@ -1635,6 +1636,23 @@ def boxplot(self, **vargs): Raises: ValueError: The Table contains columns with non-numerical values. + >>> test1_scores = [92.5, 88, 72, 71, 99, 100, 95, 83, 94, 93] + >>> test2_scores = [89, 84, 74, 66, 92, 99, 88, 81, 95, 94] + >>> table = Table([test1_scores, test2_scores], ['test1', 'test2']) + >>> table + test1 | test2 + 92.5 | 89 + 88 | 84 + 72 | 74 + 71 | 66 + 99 | 92 + 100 | 99 + 95 | 88 + 83 | 81 + 94 | 95 + 93 | 94 + >>> table.boxplot() # doctest: +SKIP + """ # Check for non-numerical values and raise a ValueError if any found for col in self: From 08b0e9190b77492090f4c2ad02383888bff3b128 Mon Sep 17 00:00:00 2001 From: Taylor Wong Date: Mon, 26 Oct 2015 02:36:04 -0700 Subject: [PATCH 3/3] fix Table#boxplot documentation --- datascience/tables.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/datascience/tables.py b/datascience/tables.py index f6599ad35..17e56df60 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1640,17 +1640,17 @@ def boxplot(self, **vargs): >>> test2_scores = [89, 84, 74, 66, 92, 99, 88, 81, 95, 94] >>> table = Table([test1_scores, test2_scores], ['test1', 'test2']) >>> table - test1 | test2 - 92.5 | 89 - 88 | 84 - 72 | 74 - 71 | 66 - 99 | 92 - 100 | 99 - 95 | 88 - 83 | 81 - 94 | 95 - 93 | 94 + test1 | test2 + 92.5 | 89 + 88 | 84 + 72 | 74 + 71 | 66 + 99 | 92 + 100 | 99 + 95 | 88 + 83 | 81 + 94 | 95 + 93 | 94 >>> table.boxplot() # doctest: +SKIP """