Ejemplo n.º 1
0
def plotDensity(data, name, pdf):
    """
    This function takes a pandas dataframe and plots a
    density plot and a boxplot.
    """
    # Stablishing figure layout (x,y,colspan,rowspan)
    axisLayout = [(0, 0, 1, 3), (3, 0, 1, 1)]

    # Creating a figure template
    figure = figureHandler(proj='2d',
                           numAx=2,
                           numRow=4,
                           numCol=1,
                           figsize=(8, 13),
                           arrangement=axisLayout)
    # Adding figure Title
    figure.formatAxis(figTitle="Distribution by Features {0}".format(name),
                      xlim="ignore",
                      ylim="ignore",
                      axnum=0,
                      showX=False)

    #Creting list of len(wide.T) maximu 50 with the colors for each index
    colors = [palette.ugColors[name]] * len(data.index)

    # Plotting boxPlot
    box.boxDF(ax=figure.ax[0], colors=colors, dat=data.T, vert=False, rot=0)

    # Plotting density plot
    density.plotDensityDF(data=data.T.unstack(),
                          ax=figure.ax[1],
                          colors=colors[0])

    # Adding figure to pdf object
    figure.addToPdf(pdf)
Ejemplo n.º 2
0
def plotDistributions(data, cutoff, palette, pdf):
    # Open new figureHandler instance
    fh = figureHandler(proj='2d', figsize=(14, 8))

    #Get xmin and xmax
    xmin = -np.nanpercentile(data['cv'].values, 99) * 0.2
    xmax = np.nanpercentile(data['cv'].values, 99) * 1.5

    # Split design file by treatment group and plot density plot
    for name, group in palette.design.groupby(palette.combName):
        dist.plotDensityDF(data=data["cv_" + name],
                           ax=fh.ax[0],
                           colors=palette.ugColors[name],
                           lb="{0}".format(name))

    # Plot legend
    fh.makeLegendLabel(ax=fh.ax[0])

    # Give format to the axis
    fh.formatAxis(
        yTitle="Density",
        xlim=(xmin, xmax),
        ylim="ignore",
        figTitle="Density Plot of Coefficients of Variation by {0}".format(
            palette.combName))

    # Shrink figure
    fh.shrink()

    # Add figure to PDF
    fh.addToPdf(pdfPages=pdf)
Ejemplo n.º 3
0
def plotDensityDistribution(pdf, wide, palette):
    # Instanciating figureHandler object
    figure = figureHandler(proj="2d", figsize=(12, 7))

    # Formating axis
    figure.formatAxis(figTitle="Distribution by Samples Density",
                      xlim="ignore",
                      ylim="ignore",
                      grid=False)

    # Plotting density plot
    density.plotDensityDF(colors=palette.design["colors"],
                          ax=figure.ax[0],
                          data=wide)

    # Add legend to the plot
    figure.makeLegend(ax=figure.ax[0],
                      ucGroups=palette.ugColors,
                      group=palette.combName)

    # Shrinking figure
    figure.shrink()

    # Adding to PDF
    figure.addToPdf(pdf, dpi=600)
Ejemplo n.º 4
0
def plotCVplots(data, cutoff, palette, pdf):
    #Iterate over groups
    for name, group in palette.design.groupby(palette.combName):
        # Open figure handler
        fh = figureHandler(proj='2d', figsize=(14, 8))

        # Get xmin and xmax
        xmin = -np.nanpercentile(data['cv_' + name].values, 99) * 0.2
        xmax = np.nanpercentile(data['cv_' + name].values, 99) * 1.5

        # Plot histogram
        hist.serHist(ax=fh.ax[0],
                     dat=data['cv_' + name],
                     color='grey',
                     normed=1,
                     range=(xmin, xmax),
                     bins=15)

        # Plot density plot
        dist.plotDensityDF(data=data['cv_' + name],
                           ax=fh.ax[0],
                           lb="CV density",
                           colors=palette.ugColors[name])

        # Plot cutoff
        lines.drawCutoffVert(ax=fh.ax[0],
                             x=cutoff[name],
                             lb="Cutoff at: {0}".format(cutoff[name]))

        # Plot legend
        fh.makeLegendLabel(ax=fh.ax[0])

        # Give format to the axis
        fh.formatAxis(
            yTitle='Density',
            xlim=(xmin, xmax),
            ylim="ignore",
            figTitle="Density Plot of Coefficients of Variation in {0}".format(
                name))

        # Shrink figure to fit legend
        fh.shrink()

        # Add plot to PDF
        fh.addToPdf(pdfPages=pdf)