Exemple #1
0
    def plot(self):
        # Keyworded arugments
        start = kw.get('start', 0)
        stop = kw.get('stop')
        showlines = kw.get('showlines', True)
        showlabel = kw.get('showlabel', True)
        traces = kw.get('traces', 0)

        # Plot options
        plot_opts = {'xmin': kw.get('xmin'),
                     'xmax': kw.get('xmax'), 
                     'ymin': kw.get('ymin', 0.75 / precision), 
                     'ymax': kw.get('ymax', 1.25 / precision), 
                     'markersize': kw.get('markersize', 3)}

        db = DB()
        last_prime = db.last_prime(f)
        total = db.count(f, True, type_=type_)
        interval = 1 / precision

        # Calculate points where we take snapshots to show traces
        snapshots = list()
        unit = total // (traces + 1)
        for n in range(traces):
            snapshots.append(unit * (n + 1))

        snapshots.append(total)

        plot = scatter_plot([])
        counts = [0, ] * precision
        n = 0
        for p in db.roots_by_partition(f, precision, type_):
            counts[p] += 1

            if n == snapshots[0]:
                del snapshots[0]
                plot += plot_density([i / n for i in counts], 
                                     alpha=(n/total), **plot_opts)
            n += 1

        plot += plot_density([i / total for i in counts], show_lines=True,  **plot_opts)

        self.plot = plot
Exemple #2
0
    def __init__(self, f, **kw):
        """Create a density plot.

        Arguments:
        f -- Polynomial in database
        precision -- Number of bins
        type_ -- Type of roots

        Keyword Arguments:
        
        """
        self.f = f
        self.degree = f.degree()
        self.group = f.galois_group()._n
        
        self.precision = kw.get("precision", self.defaults["precision"])
        self.type_ = type_

        db = DB()
        self.count = db.count(f)
        self.last_prime = db.last_prime(f)