Esempio n. 1
0
def plot(df, cut_name,
         my_variables=False, save=False):

    if my_variables is None:
        my_variables = variables.get_variables()

    df_reduced = variables.reduce_df(df,
                                     my_variables)
    print('%s: %d of %d events not shown out of plotting window' % (cut_name,
                                                                     df['x'].count() - df_reduced['x'].count(),
                                                                     df['x'].count()))

    name = '%s Cut' % cut_name
    df_reduced[name] = ['Pass' if x == True else 'Fail' for x in df_reduced[cut_name]]

    number_passing = df_reduced[cut_name].sum()
    total = df_reduced['x'].count()


    if number_passing == total:
        print('Not plotting, no removed events for', cut_name)
        return

    keys = list(my_variables.keys())

    g = sns.PairGrid(df_reduced,
                     vars=keys,
                     diag_sharey=False,
                     hue_order=['Pass', 'Fail'],
                     palette=['green', 'red', ],
                     hue=name,
                     hue_kws={"cmap": ["Greens", "Reds", ],
                              "marker": ["o", "x"]})
    g.map_lower(sns.kdeplot, shade=True,
                n_levels=10,
                shade_lowest=False, alpha=0.5, )
    g.map_upper(plt.scatter, alpha=0.2)
    g.map_diag(plt.hist, histtype="step", linewidth=3)
    g.add_legend()

    for i, ax in enumerate(g.axes.flat):
        ax.set_xlim(my_variables[keys[i % len(my_variables)]]['range'])
        ax.set_ylim(my_variables[keys[int(i / len(my_variables))]]['range'])

    if save:
        for extension in ['pdf', 'png', 'eps']:
            plt.savefig('plots/%s_%d.%s' % (cut_name,
                                             len(my_variables),
                                            extension),
                        bbox_inches='tight')
    else:
        plt.show()
Esempio n. 2
0
    def plot_conv_qpgap(self, x_vars, **kwargs):
        """
        Plot the convergence of the Quasi-particle gap.
        kwargs are passed to :class:`seaborn.PairGrid`.
        """
        import matplotlib.pyplot as plt
        import seaborn.apionly as sns

        data = self.get_qpgaps_dataframe()
        grid = sns.PairGrid(data, x_vars=x_vars, y_vars="qpgap", **kwargs)
        grid.map(plt.plot, marker="o")
        grid.add_legend()
        plt.show()
Esempio n. 3
0
 def _update_plot(self, axis, view):
     if self.plot_type == 'regplot':
         sns.regplot(x=view.x,
                     y=view.y,
                     data=view.data,
                     ax=axis,
                     **self.style)
     elif self.plot_type == 'boxplot':
         self.style.pop('return_type', None)
         self.style.pop('figsize', None)
         sns.boxplot(view.data[view.y],
                     view.data[view.x],
                     ax=axis,
                     **self.style)
     elif self.plot_type == 'violinplot':
         sns.violinplot(view.data[view.y],
                        view.data[view.x],
                        ax=axis,
                        **self.style)
     elif self.plot_type == 'interact':
         sns.interactplot(view.x,
                          view.x2,
                          view.y,
                          data=view.data,
                          ax=axis,
                          **self.style)
     elif self.plot_type == 'corrplot':
         sns.corrplot(view.data, ax=axis, **self.style)
     elif self.plot_type == 'lmplot':
         sns.lmplot(x=view.x,
                    y=view.y,
                    data=view.data,
                    ax=axis,
                    **self.style)
     elif self.plot_type in ['pairplot', 'pairgrid', 'facetgrid']:
         map_opts = [(k, self.style.pop(k)) for k in self.style.keys()
                     if 'map' in k]
         if self.plot_type == 'pairplot':
             g = sns.pairplot(view.data, **self.style)
         elif self.plot_type == 'pairgrid':
             g = sns.PairGrid(view.data, **self.style)
         elif self.plot_type == 'facetgrid':
             g = sns.FacetGrid(view.data, **self.style)
         for opt, args in map_opts:
             plot_fn = getattr(sns, args[0]) if hasattr(
                 sns, args[0]) else getattr(plt, args[0])
             getattr(g, opt)(plot_fn, *args[1:])
         plt.close(self.handles['fig'])
         self.handles['fig'] = plt.gcf()
     else:
         super(SNSFramePlot, self)._update_plot(axis, view)
Esempio n. 4
0
 def _update_plot(self, axis, view):
     style = self._process_style(self.style[self.cyclic_index])
     if self.plot_type == 'factorplot':
         opts = dict(style, **({'hue': view.x2} if view.x2 else {}))
         sns.factorplot(x=view.x, y=view.y, data=view.data, **opts)
     elif self.plot_type == 'regplot':
         sns.regplot(x=view.x, y=view.y, data=view.data, ax=axis, **style)
     elif self.plot_type == 'boxplot':
         style.pop('return_type', None)
         style.pop('figsize', None)
         sns.boxplot(view.data[view.y], view.data[view.x], ax=axis, **style)
     elif self.plot_type == 'violinplot':
         if view.x:
             sns.violinplot(view.data[view.y],
                            view.data[view.x],
                            ax=axis,
                            **style)
         else:
             sns.violinplot(view.data, ax=axis, **style)
     elif self.plot_type == 'interact':
         sns.interactplot(view.x,
                          view.x2,
                          view.y,
                          data=view.data,
                          ax=axis,
                          **style)
     elif self.plot_type == 'corrplot':
         sns.corrplot(view.data, ax=axis, **style)
     elif self.plot_type == 'lmplot':
         sns.lmplot(x=view.x, y=view.y, data=view.data, ax=axis, **style)
     elif self.plot_type in ['pairplot', 'pairgrid', 'facetgrid']:
         style_keys = list(style.keys())
         map_opts = [(k, style.pop(k)) for k in style_keys if 'map' in k]
         if self.plot_type == 'pairplot':
             g = sns.pairplot(view.data, **style)
         elif self.plot_type == 'pairgrid':
             g = sns.PairGrid(view.data, **style)
         elif self.plot_type == 'facetgrid':
             g = sns.FacetGrid(view.data, **style)
         for opt, args in map_opts:
             plot_fn = getattr(sns, args[0]) if hasattr(
                 sns, args[0]) else getattr(plt, args[0])
             getattr(g, opt)(plot_fn, *args[1:])
         plt.close(self.handles['fig'])
         self.handles['fig'] = plt.gcf()
     else:
         super(SNSFramePlot, self)._update_plot(axis, view)
Esempio n. 5
0
    def pairplot(self, data=None, getter="get_dataframe", map_kws=None, show=True, **kwargs):
        # TODO: Remove
        import matplotlib.pyplot as plt
        import seaborn.apionly as sns
        if data is None:
            data = getattr(self, getter)()

        #grid = sns.PairGrid(data, x_vars="nkpt", y_vars=["a", "volume"]) #, hue="tsmear")
        grid = sns.PairGrid(data, **kwargs)
        if map_kws is None:
            grid.map(plt.plot, marker="o")
        else:
            func = map_kws.pop("func", plt.plot)
            grid.map(func, **map_kws)

        grid.add_legend()
        if show: plt.show()
        return grid
Esempio n. 6
0
    def plot_conv_phfreqs_qpoint(self, x_vars, qpoint=None, **kwargs):
        """
        Plot the convergence of the phonon frequencies.
        kwargs are passed to :class:`seaborn.PairGrid`.
        """
        import matplotlib.pyplot as plt
        import seaborn.apionly as sns

        # Get the dataframe for this q-point.
        data = self.get_dataframe_at_qpoint(qpoint=qpoint)

        y_vars = sorted([k for k in data if k.startswith("mode")])
        #print(y_vars)

        # Call seaborn.
        grid = sns.PairGrid(data, x_vars=x_vars, y_vars=y_vars, **kwargs)
        grid.map(plt.plot, marker="o")
        grid.add_legend()
        plt.show()
Esempio n. 7
0
def plot_synapse_pairs(X, zh, output='synapse_pairs.pdf'):
    sns.set_style({"font.size": 10, "axes.labelsize": 30})
    d = {'z': zh}
    n, p = X.shape
    for i in range(p):
        d[r'$x_{%i}$' % (i + 1)] = X[:, i]
        #d[r'$x_{%i}$'%(i+1)] = X[:,i]/(10**5)
    df = pd.DataFrame(data=d)
    g = sns.PairGrid(df,
                     hue="z",
                     vars=[r'$x_{%i}$' % (i + 1) for i in range(p)])

    def scatter_fake_diag(x, y, *a, **kw):
        if x.equals(y):
            kw["color"] = (0, 0, 0, 0)
        plt.scatter(x, y, s=3, *a, **kw)

    g.map(scatter_fake_diag)
    g.map_diag(plt.hist)
    g.savefig(output)