示例#1
0
文件: other.py 项目: mphilli/corpkit
def interroplot(path, query):
    import corpkit
    """Interrogates path with Tregex query, gets relative frequencies, and plots the top seven results"""
    from corpkit import interrogator, editor, plotter
    quickstart = interrogator(path, 'words', query)
    edited = editor(quickstart.results, '%', quickstart.totals, print_info = False)
    plotter(str(path), edited.results)
示例#2
0
文件: other.py 项目: whrl/corpkit
def interroplot(path, query):
    """Demo function for interrogator/plotter.

        1. Interrogates path with Tregex query, 
        2. Gets relative frequencies
        3. Plots the top seven results

    :param path: path to corpus
    :type path: str
    
    :param query: Tregex query
    :type query: str

    """
    import corpkit
    from corpkit import interrogator, editor, plotter
    quickstart = interrogator(path, 'words', query, show = ['w'])
    edited = editor(quickstart.results, '%', quickstart.totals, print_info = False)
    plotter(str(path), edited.results)
示例#3
0
# If you want to see the query and options that created the results, you can use:

# <codecell>
print allwords.query

# <markdowncell>
# ### Plotting results

# <markdowncell>
# Lists of years and totals are pretty dry. Luckily, we can use the `plotter()` function to visualise our results. At minimum, `plotter()` needs two arguments:

# 1. a title (in quotation marks)
# 2. a list of results to plot

# <codecell>
plotter('Word counts in each subcorpus', allwords.totals)

# <markdowncell>
# Because we have smaller samples for 1963 and 2014, we might want to project them. To do that, we can pass subcorpus names and projection values to `editor()`:

# <codecell>
proj_vals = [(1963, 5), (2014, 1.37)]
projected = editor(allwords.totals, projection = proj_vals)
plotter('Word counts in each subcorpus (projected)', projected.totals)

# <markdowncell>
# Great! So, we can see that the number of words per year varies quite a lot, even after projection. That's worth keeping in mind.

# <markdowncell>
# ### Frequency of risk words in the NYT
示例#4
0
 def plot(self, title, *args, **kwargs):
     """calls corpkit.plotter.plotter()"""
     from corpkit import plotter
     plotter(title, self, *args, **kwargs)
示例#5
0
    def plot(title,
            x_label = None,
            y_label = None,
            style = 'ggplot',
            figsize = (8, 4),
            save = False,
            legend_pos = 'best',
            reverse_legend = 'guess',
            num_to_plot = 7,
            tex = 'try',
            colours = 'Accent',
            cumulative = False,
            pie_legend = True,
            partial_pie = False,
            show_totals = False,
            transparent = False,
            output_format = 'png',
            interactive = False,
            black_and_white = False,
            show_p_val = False,
            indices = False,
            **kwargs):
        """Visualise corpus interrogations.

           >>> data.plot('An example plot', kind = 'bar', save = True)

        :param title: A title for the plot
        :type title: str
        :param x_label: A label for the x axis
        :type x_label: str
        :param y_label: A label for the y axis
        :type y_label: str
        :param kind: The kind of chart to make
        :type kind: str ('line'/'bar'/'barh'/'pie'/'area')
        :param style: Visual theme of plot
        :type style: str ('ggplot'/'bmh'/'fivethirtyeight'/'seaborn-talk'/etc)
        :param figsize: Size of plot
        :type figsize: tuple (int, int)
        :param save: If bool, save with *title* as name; if str, use str as name
        :type save: bool/str
        :param legend_pos: Where to place legend
        :type legend_pos: str ('upper right'/'outside right'/etc)
        :param reverse_legend: Reverse the order of the legend
        :type reverse_legend: bool
        :param num_to_plot: How many columns to plot
        :type num_to_plot: int/'all'
        :param tex: Use TeX to draw plot text
        :type tex: bool
        :param colours: Colourmap for lines/bars/slices
        :type colours: str
        :param cumulative: Plot values cumulatively
        :type cumulative: bool
        :param pie_legend: Show a legend for pie chart
        :type pie_legend: bool
        :param partial_pie: Allow plotting of pie slices only
        :type partial_pie: bool
        :param show_totals: Print sums in plot where possible
        :type show_totals: str -- 'legend'/'plot'/'both'
        :param transparent: Transparent .png background
        :type transparent: bool
        :param output_format: File format for saved image
        :type output_format: str -- 'png'/'pdf'
        :param black_and_white: Create black and white line styles
        :type black_and_white: bool
        :param show_p_val: Attempt to print p values in legend if contained in df
        :type show_p_val: bool
        :param indices: To use when plotting "distance from root"
        :type indices: bool
        :param stacked: When making bar chart, stack bars on top of one another
        :type stacked: str
        :param filled: For area and bar charts, make every column sum to 100
        :type filled: str
        :param legend: Show a legend
        :type legend: bool
        :param rot: Rotate x axis ticks by *rot* degrees
        :type rot: int
        :param subplots: Plot each column separately
        :type subplots: bool
        :param layout: Grid shape to use when *subplots* is True
        :type layout: tuple -- (int, int)
        :param interactive: Experimental interactive options
        :type interactive: list -- [1, 2, 3]
        :returns: matplotlib figure
        """
        from corpkit import plotter
        branch = kwargs.pop('branch', 'results')
        if branch.lower().startswith('r'):
            plotter(title, self.results, *args, **kwargs)
        elif branch.lower().startswith('t'):
            plotter(title, self.totals, *args, **kwargs)