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)
def plotBoxplotDistribution(pdf, wide, palette): # Instanciating figureHandler object figure = figureHandler(proj="2d", figsize=(max(len(wide.columns) / 4, 12), 7)) # Formating axis figure.formatAxis(figTitle="Distribution by Samples Boxplot", ylim="ignore", grid=False, xlim="ignore") # Plotting boxplot box.boxDF(ax=figure.ax[0], colors=palette.design["colors"], dat=wide) # Shrinking figure figure.shrink() #Adding to PDF figure.addToPdf(pdf, dpi=600)
def plotDistances(df_distance, palette, plotType, disType, cutoff, p, pdf): #Geting number of samples in dataframe (ns stands for number of samples) ns = len(df_distance.index) #Calculates the widht for the figure base on the number of samples figWidth = max(ns / 2, 16) # Keeping the order on the colors df_distance["colors"] = palette.design["colors"] # Create figure object with a single axis figure = figureHandler(proj='2d', figsize=(figWidth, 8)) # Getting type of distance file if "distance_to_mean" in df_distance.columns: dataType = "to the mean" else: dataType = "pairwise" # Getting ty of distance header if disType == "Mahalanobis": distType1 = "Penalized" distType2 = disType else: distType1 = "Standardized" distType2 = disType # Adds Figure title, x axis limits and set the xticks figure.formatAxis(figTitle="{0} for {1} {2} Distance for {3} {4}".format( plotType, distType1, distType2, df_distance.name, dataType), yTitle="{0} {1} Distance".format(distType1, distType2), xTitle="Index", ylim="ignore", xlim=(-0.5, -0.5 + ns), xticks=df_distance.index) # If distance to mean if dataType == "to the mean": # Plot scatterplot quickplot scatter.scatter2D(ax=figure.ax[0], colorList=df_distance["colors"], x=range(len(df_distance.index)), y=df_distance["distance_to_mean"]) # if pairwise else: if plotType == "Scatterplot": # Plot scatterplot for index in df_distance.index: scatter.scatter2D(ax=figure.ax[0], colorList=df_distance["colors"][index], x=range(len(df_distance.index)), y=df_distance[index]) elif plotType == "Box-plots": # Plot Box plot box.boxDF(ax=figure.ax[0], colors=df_distance["colors"], dat=df_distance) # Shrink figure figure.shrink() # Plot legend figure.makeLegend(figure.ax[0], palette.ugColors, palette.combName) #Add a cutoof line cutoff.apply(lambda x: plotCutoffs(x, ax=figure.ax[0], p=p), axis=0) # Add figure to PDF and close the figure afterwards figure.addToPdf(pdf) # Drop "color" column to no mess the results df_distance.drop("colors", axis=1, inplace=True)
def makePlots(SEDData, design, pdf, groupName, cutoff, p, plotType, ugColors, levels): """ Manage all the plots for this script :Arguments: :type SEDData: pandas.dataFrame :param SEDData: Contains SED data either to Mean or pairwise :type design: pandas.dataFrame :param design: Design file after getColor :type pdf: PDF object :param pdf: PDF for output plots :type groupName: string :param groupName: Name of the group (figure title). :type cutoff: pandas.dataFrame :param cutoff: Cutoff values, beta, chi-sqr and normal. :type p: float :param p: Percentil for cutoff. :type plotType: string :param plotType: Type of plot, the possible types are scatterplot to mean scatterplot pairwise and boxplot pairwise. """ #Geting number of features in dataframe nFeatures = len(SEDData.index) #Calculates the widht for the figure base on the number of features figWidth = max(nFeatures / 2, 16) # Create figure object with a single axis and initiate the figss figure = figureHandler(proj='2d', figsize=(figWidth, 8)) # Keeping the order on the colors SEDData["colors"] = design["colors"] # Choose type of plot # Plot scatterplot to mean if (plotType == "scatterToMean"): #Adds Figure title, x axis limits and set the xticks figure.formatAxis( figTitle= "Standardized Euclidean Distance from samples {} to the mean". format(groupName), xlim=(-0.5, -0.5 + nFeatures), ylim="ignore", xticks=SEDData.index.values, xTitle="Index", yTitle="Standardized Euclidean Distance") #Plot scatterplot quickplot scatter.scatter2D(ax=figure.ax[0], colorList=SEDData["colors"], x=range(len(SEDData.index)), y=SEDData["SED_to_Mean"]) #Plot scatterplot pairwise elif (plotType == "scatterPairwise"): # Adds Figure title, x axis limits and set the xticks figure.formatAxis( figTitle="Pairwise standardized Euclidean Distance from samples {}" .format(groupName), xlim=(-0.5, -0.5 + nFeatures), ylim="ignore", xticks=SEDData.index.values, xTitle="Index", yTitle="Standardized Euclidean Distance") # Plot scatterplot for index in SEDData.index.values: scatter.scatter2D(ax=figure.ax[0], colorList=design["colors"][index], x=range(len(SEDData.index)), y=SEDData[index]) #Plot boxplot pairwise elif (plotType == "boxplotPairwise"): # Add Figure title, x axis limits and set the xticks figure.formatAxis( figTitle= "Box-plots for pairwise standardized Euclidean Distance from samples {}" .format(groupName), xlim=(-0.5, -0.5 + nFeatures), ylim="ignore", xticks=SEDData.index.values, xTitle="Index", yTitle="Standardized Euclidean Distance") # Plot Box plot box.boxDF(ax=figure.ax[0], colors=SEDData["colors"].values, dat=SEDData) #Add a cutoof line cutoff.apply(lambda x: plotCutoffs(x, ax=figure.ax[0], p=p), axis=0) figure.shrink() # Plot legend #if group: figure.makeLegend(figure.ax[0], ugColors, levels) # Add figure to PDF and close the figure afterwards figure.addToPdf(pdf)