From 803835d4997a4dee1022abdb5982f86b118a041d Mon Sep 17 00:00:00 2001 From: Taylor Wong Date: Sat, 28 Nov 2015 04:50:32 -0800 Subject: [PATCH 1/2] fix scatter axes labels #146 --- datascience/tables.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/datascience/tables.py b/datascience/tables.py index 2376bb92b..fdd095384 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1400,6 +1400,7 @@ def scatter(self, column_for_x, overlay=False, fit_line=False, **vargs): options = self.default_options.copy() options.update(vargs) xdata, labels = self._split_by_column(column_for_x) + labels = [(column_for_x, y) for y in labels] def draw(axis, label, color): axis.scatter(xdata, self[label], color=color, **options) @@ -1597,8 +1598,13 @@ def _visualize(self, labels, ticks, overlay, draw, annotate, width=6, height=4): if not isinstance(axes, collections.Iterable): axes=[axes] for axis, label, color in zip(axes, labels, colors): - draw(axis, label, color) - axis.set_xlabel(label, fontsize=16) + if isinstance(label, tuple): + draw(axis, label[1], color) + axis.set_xlabel(label[0], fontsize=16) + axis.set_ylabel(label[1], fontsize=16) + else: + draw(axis, label, color) + axis.set_xlabel(label, fontsize=16) if ticks is not None: annotate(axis, ticks) From c760aa9dfaf28e6c0337100e591075ca12a43909 Mon Sep 17 00:00:00 2001 From: Taylor Wong Date: Sat, 28 Nov 2015 05:42:51 -0800 Subject: [PATCH 2/2] fix axes labels for plot, barh, bar #146 --- datascience/tables.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/datascience/tables.py b/datascience/tables.py index fdd095384..5e36174d7 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1316,11 +1316,8 @@ def plot(self, column_for_xticks, overlay=False, **vargs): options = self.default_options.copy() options.update(vargs) - # Note that the labels here get incorrectly placed on the x-axis even - # though the labels describe the y-axis values. - # TODO(sam): Allow _visualize to accept options to put labels on both x - # and y axes. xticks, labels = self._split_by_column(column_for_xticks) + labels = [(column_for_xticks, y) for y in labels] def draw(axis, label, color): if xticks is None: @@ -1493,6 +1490,7 @@ def barh(self, column_for_categories, overlay=False, **vargs): raise ValueError("The column '{0}' contains non-numerical " "values. A bar graph cannot be drawn for this table." .format(label)) + labels = [(column_for_categories, y) for y in labels] index = np.arange(self.num_rows) margin = 0.1 @@ -1561,6 +1559,7 @@ def bar(self, column_for_categories=None, overlay=False, **vargs): raise ValueError("The column '{0}' contains non-numerical " "values. A bar graph cannot be drawn for this table." .format(label)) + labels = [(column_for_categories, y) for y in labels] index = np.arange(self.num_rows) margin = 0.1