def plot_quantile_returns_violin(return_by_q,
                                 ylim_percentiles=None,
                                 ax=None):
    """
    Plots a violin box plot of period wise returns for factor quantiles.

    Parameters
    ----------
    return_by_q : pd.DataFrame - MultiIndex
        DataFrame with date and quantile as rows MultiIndex,
        forward return windows as columns, returns as values.
    ylim_percentiles : tuple of integers
        Percentiles of observed data to use as y limits for plot.
    ax : matplotlib.Axes, optional
        Axes upon which to plot.

    Returns
    -------
    ax : matplotlib.Axes
        The axes that were plotted on.
    """

    return_by_q = return_by_q.copy()

    if ylim_percentiles is not None:
        ymin = (np.nanpercentile(return_by_q.values,
                                 ylim_percentiles[0]) * DECIMAL_TO_BPS)
        ymax = (np.nanpercentile(return_by_q.values,
                                 ylim_percentiles[1]) * DECIMAL_TO_BPS)
    else:
        ymin = None
        ymax = None

    if ax is None:
        f, ax = plt.subplots(1, 1, figsize=(18, 6))

    unstacked_dr = (return_by_q
                    .multiply(DECIMAL_TO_BPS))
    unstacked_dr.columns = unstacked_dr.columns.set_names('forward_periods')
    unstacked_dr = unstacked_dr.stack()
    unstacked_dr.name = 'return'
    unstacked_dr = unstacked_dr.reset_index()

    sns.violinplot(data=unstacked_dr,
                   x='factor_quantile',
                   hue='forward_periods',
                   y='return',
                   orient='v',
                   cut=0,
                   inner='quartile',
                   ax=ax)
    ax.set(xlabel='', ylabel='Return (bps)',
           title="Period Wise Return By Factor Quantile",
           ylim=(ymin, ymax))

    ax.axhline(0.0, linestyle='-', color='black', lw=0.7, alpha=0.6)

    return ax
def plot_quantile_returns_violin ( return_by_q , ylim_percentiles = None , ax = None ) : return_by_q = return_by_q . copy ( ) if ylim_percentiles is not None : ymin = ( np . nanpercentile ( return_by_q . values , ylim_percentiles [ 0 ] ) * DECIMAL_TO_BPS ) ymax = ( np . nanpercentile ( return_by_q . values , ylim_percentiles [ 1 ] ) * DECIMAL_TO_BPS ) else : ymin = None ymax = None if ax is None : f , ax = plt . subplots ( 1 , 1 , figsize = ( 18 , 6 ) ) unstacked_dr = ( return_by_q . multiply ( DECIMAL_TO_BPS ) ) unstacked_dr . columns = unstacked_dr . columns . set_names ( 'forward_periods' ) unstacked_dr = unstacked_dr . stack ( ) unstacked_dr . name = 'return' unstacked_dr = unstacked_dr . reset_index ( ) sns . violinplot ( data = unstacked_dr , x = 'factor_quantile' , hue = 'forward_periods' , y = 'return' , orient = 'v' , cut = 0 , inner = 'quartile' , ax = ax ) ax . set ( xlabel = '' , ylabel = 'Return (bps)' , title = "Period Wise Return By Factor Quantile" , ylim = ( ymin , ymax ) ) ax . axhline ( 0.0 , linestyle = '-' , color = 'black' , lw = 0.7 , alpha = 0.6 ) return ax
Plots a violin box plot of period wise returns for factor quantiles.

    Parameters
    ----------
    return_by_q : pd.DataFrame - MultiIndex
        DataFrame with date and quantile as rows MultiIndex,
        forward return windows as columns, returns as values.
    ylim_percentiles : tuple of integers
        Percentiles of observed data to use as y limits for plot.
    ax : matplotlib.Axes, optional
        Axes upon which to plot.

    Returns
    -------
    ax : matplotlib.Axes
        The axes that were plotted on.