예제 #1
0
def volcano_plot(df: pd.DataFrame, ax: matplotlib.axes.Axes) -> matplotlib.axes.Axes:
    '''Generate a volcano plot

    Parameters
    ----------
    df : pd.DataFrame
        differential expression output from `diffex_multifactor`.
    ax : matplotlib.axes.Axes

    Returns
    -------
    matplotlib.axes.Axes
    '''
    if 'significant' not in df.columns:
        print('Adding significance cutoff at alpha=0.05')
        df['significant'] = df['q_val'] < 0.05

    n_colors = len(np.unique(df['significant']))
    sns.scatterplot(data=df, x='log2_fc', y='nlogq', hue='significant',
                    linewidth=0.,
                    alpha=0.3,
                    ax=ax,
                    palette=sns.hls_palette(n_colors)[::-1])
    ax.set_xlim((-6, 6))
    ax.set_ylabel(r'$-\log_{10}$ q-value')
    ax.set_xlabel(r'$\log_2$ (Old / Young)')
    ax.get_legend().remove()
    return ax
예제 #2
0
    def _toggle_legend(self, ax: matplotlib.axes.Axes,  pad_h: float) -> None:
        '''
        Update legends according to those curves on the canvas.
        Clear and remove all legend instance if no curves on the canvas.
        Set legend to invisible but still keeping all legend instances existed
        if user choose to hide legend in the axes parameter dialog.
        Those customized setting are stored in ``parameter``.
        '''
        handles, labels = self._sort_legend(ax)
        if ax == self.ax_main:
            loc = "upper left"
            leg_bottom = 0.5
        else:
            loc = "lower left"
            leg_bottom = 0

        if labels:
            ax.legend(handles, labels, bbox_to_anchor=(1+pad_h, leg_bottom, 1, .5),
                      loc=loc, borderaxespad=0)
            legend_visible = self.parameter["General"]["Legend"]["visible"]
            print(ax.get_title(), legend_visible)
            ax.get_legend().set_visible(legend_visible)
        else:
            leg = ax.legend([])
            leg.remove()