Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,12 @@ def hist(self, overlay=False, bins=None, counts=None, **vargs):
>>> table.hist() # doctest: +SKIP
<histogram of values in count>
<histogram of values in points>

>>> value = [101, 102, 103]
>>> prop = [0.25, 0.5, 0.25]
>>> t = Table([value, prop], ['value', 'proportion'])
>>> t.hist(counts='value') # doctest: +SKIP
<histogram of values in prop weighted by corresponding values in value>
"""
# Check for non-numerical values and raise a ValueError if any found
for col in self:
Expand All @@ -1580,11 +1586,13 @@ def hist(self, overlay=False, bins=None, counts=None, **vargs):
bins = np.unique(self[bins])
vargs['bins'] = bins

counted_values = None
counted_values = counted_label = None
if counts is not None:
counted_values = self._get_column(counts)
counted_label = 'counts'
if isinstance(counts, collections.Hashable) and counts in self.column_labels:
columns.pop(counts)
counted_label = counts

n = len(columns)
colors = [rgb_color + (self.default_hist_alpha,) for rgb_color in
Expand All @@ -1606,11 +1614,12 @@ def hist(self, overlay=False, bins=None, counts=None, **vargs):
for axis, label, color in zip(axes, columns.keys(), colors):
if counted_values is None:
values = columns[label]
axis.set_xlabel(label, fontsize=16)
else:
values = counted_values
axis.set_xlabel(counted_label, fontsize=16)
vargs['weights'] = columns[label]
axis.hist(values, color=color, **vargs)
axis.set_xlabel(label, fontsize=16)

def points(self, column__lat, column__long, labels=None, colors=None, **kwargs) :
latitudes = self._get_column(column__lat)
Expand Down