Commit b4693ad2 by Steven Bird

plot and tabulate again provide samples in sorted order, optionally the first n;…

plot and tabulate again provide samples in sorted order, optionally the first n; support for slice range is dropped; resolves issue #723
parent 51105f69
...@@ -44,7 +44,6 @@ import random ...@@ -44,7 +44,6 @@ import random
import warnings import warnings
import array import array
from operator import itemgetter from operator import itemgetter
from itertools import islice
from collections import defaultdict from collections import defaultdict
from functools import reduce from functools import reduce
from nltk import compat from nltk import compat
...@@ -218,9 +217,7 @@ class FreqDist(Counter): ...@@ -218,9 +217,7 @@ class FreqDist(Counter):
Plot samples from the frequency distribution Plot samples from the frequency distribution
displaying the most frequent sample first. If an integer displaying the most frequent sample first. If an integer
parameter is supplied, stop after this many samples have been parameter is supplied, stop after this many samples have been
plotted. If two integer parameters m, n are supplied, plot a plotted. For a cumulative plot, specify cumulative=True.
subset of the samples, beginning with m and stopping at n-1.
For a cumulative plot, specify cumulative=True.
(Requires Matplotlib to be installed.) (Requires Matplotlib to be installed.)
:param title: The title for the graph :param title: The title for the graph
...@@ -236,7 +233,7 @@ class FreqDist(Counter): ...@@ -236,7 +233,7 @@ class FreqDist(Counter):
if len(args) == 0: if len(args) == 0:
args = [len(self)] args = [len(self)]
samples = list(islice(self, *args)) samples = [item for item, _ in self.most_common(*args)]
cumulative = _get_kwarg(kwargs, 'cumulative', False) cumulative = _get_kwarg(kwargs, 'cumulative', False)
if cumulative: if cumulative:
...@@ -264,16 +261,14 @@ class FreqDist(Counter): ...@@ -264,16 +261,14 @@ class FreqDist(Counter):
Tabulate the given samples from the frequency distribution (cumulative), Tabulate the given samples from the frequency distribution (cumulative),
displaying the most frequent sample first. If an integer displaying the most frequent sample first. If an integer
parameter is supplied, stop after this many samples have been parameter is supplied, stop after this many samples have been
plotted. If two integer parameters m, n are supplied, plot a plotted.
subset of the samples, beginning with m and stopping at n-1.
(Requires Matplotlib to be installed.)
:param samples: The samples to plot (default is all samples) :param samples: The samples to plot (default is all samples)
:type samples: list :type samples: list
""" """
if len(args) == 0: if len(args) == 0:
args = [len(self)] args = [len(self)]
samples = list(islice(self, *args)) samples = [item for item, _ in self.most_common(*args)]
cumulative = _get_kwarg(kwargs, 'cumulative', False) cumulative = _get_kwarg(kwargs, 'cumulative', False)
if cumulative: if cumulative:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment