From 01ea826b397cd54dae5f42d093653c2ecdd15be6 Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Tue, 27 Oct 2015 17:55:36 -0700 Subject: [PATCH] Fix bug in xticks for Table.plot() Before, calling Table([np.arange(0, 10, .1), np.arange(0, 1, .01)], ['x', 'y']).plot('x') Would show xticks of 0, 0.1, 0.2, etc. instead of 0, 2, 4, ... This was beacuse we assumed that the horizontal axis values as passed in the `ticks` variable were integers. Instead, we should just ask the axis for the ticks it used to plot the data. To test: ```python a = Table([np.arange(0, 10, .1), np.arange(0, 1, .01)], ['x', 'y']) a.plot('x') b = Table([np.arange(0, 20, .1), np.arange(0, 2, .01)], ['x', 'y']) b.plot('x') --- datascience/tables.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/datascience/tables.py b/datascience/tables.py index a8341ef39..fe9730da6 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1311,22 +1311,26 @@ def to_array(self): 'alpha': 0.8, } - def plot(self, column_for_xticks=None, overlay=False, **vargs): + def plot(self, column_for_xticks, overlay=False, **vargs): """Plot contents as lines.""" 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) def draw(axis, label, color): if xticks is None: axis.plot(self[label], color=color, **options) - else : + else: axis.plot(xticks, self[label], color=color, **options) def annotate(axis, ticks): - tick_labels = [ticks[int(l)] for l in axis.get_xticks() if l