Exemplo n.º 1
0
def grade_pie(trials_df,
              ax=None,
              figsize=None,
              colors=PIE_COLORS,
              text_size=16):
    tight = False

    if ax is None:
        if figsize is None:
            figsize = (5, 5)
        pyplot.figure(figsize=figsize)
        ax = pyplot.axes()
        tight = True

    perfect = sum(trials_df["grade_value"] == 10)
    correct = sum(trials_df["grade_value"] >= 7) - perfect
    common_error = sum(trials_df["grade_category"].str.startswith("common"))
    incorrect = len(trials_df) - perfect - correct - common_error

    bins = [perfect, correct, incorrect, common_error]

    patches, _, _ = ax.pie(bins,
                           autopct="%1.1f%%",
                           shadow=False,
                           colors=colors)
    shade_axis(ax, size=text_size)

    if tight:
        ax.figure.tight_layout()

    ax.legend(patches, ["Perfect", "Correct", "Incorrect", "Common Error"],
              loc="lower left",
              ncol=2)

    return ax
Exemplo n.º 2
0
def grade_pie(trials_df, ax=None, figsize=None, colors=PIE_COLORS, text_size=16):
    tight = False

    if ax is None:
        if figsize is None:
            figsize = (5, 5)
        pyplot.figure(figsize=figsize)
        ax = pyplot.axes()
        tight = True

    perfect = sum(trials_df["grade_value"] == 10)
    correct = sum(trials_df["grade_value"] >= 7) - perfect
    common_error = sum(trials_df["grade_category"].str.startswith("common"))
    incorrect = len(trials_df) - perfect - correct - common_error

    bins = [perfect, correct, incorrect, common_error]

    patches, _, _ = ax.pie(bins, autopct="%1.1f%%", shadow=False, colors=colors)
    shade_axis(ax, size=text_size)

    if tight:
        ax.figure.tight_layout()

    ax.legend(patches, ["Perfect", "Correct", "Incorrect", "Common Error"], loc="lower left", ncol=2)

    return ax
Exemplo n.º 3
0
def grade_pie(df, base, versions):
    """Pie chart of grade distribution for all versions of a program"""
    perfect = 0
    correct = 0
    common_error = 0
    incorrect = 0

    fig = pyplot.figure(figsize=(len(versions) * 5, 5))
    for i, v in enumerate(versions):
        v_rows = df[(df["base"] == base) & (df["version"] == v)]
        ax = fig.add_subplot(1, len(versions), i + 1)
        ax.set_title(v)
        for _, row in v_rows.iterrows():
            grade_category = row["grade_category"]
            grade_value = int(row["grade_value"])

            if grade_value == 10:
                perfect += 1
            elif grade_value >= 7:
                correct += 1
            elif "common" in grade_category:
                common_error += 1
            else:
                incorrect += 1

        bins = [perfect, correct, incorrect, common_error]
        patches, _, _ = ax.pie(bins, autopct="%1.1f%%", shadow=False, colors=colors)
        shade_axis(ax)

    # fig.suptitle(base)
    pyplot.tight_layout()
    pyplot.legend(patches, ["Perfect", "Correct", "Incorrect", "Common Error"], loc="lower left", ncol=2)

    pyplot.savefig("plots/grade_pie-{0}.png".format(base))
Exemplo n.º 4
0
def grade_pie(df, base, versions):
    """Pie chart of grade distribution for all versions of a program"""
    perfect = 0
    correct = 0
    common_error = 0
    incorrect = 0

    fig = pyplot.figure(figsize=(len(versions) * 5, 5))
    for i, v in enumerate(versions):
        v_rows = df[(df["base"] == base) & (df["version"] == v)]
        ax = fig.add_subplot(1, len(versions), i + 1)
        ax.set_title(v)
        for _, row in v_rows.iterrows():
            grade_category = row["grade_category"]
            grade_value = int(row["grade_value"])

            if grade_value == 10:
                perfect += 1
            elif grade_value >= 7:
                correct += 1
            elif "common" in grade_category:
                common_error += 1
            else:
                incorrect += 1

        bins = [perfect, correct, incorrect, common_error]
        patches, _, _ = ax.pie(bins,
                               autopct="%1.1f%%",
                               shadow=False,
                               colors=colors)
        shade_axis(ax)

    #fig.suptitle(base)
    pyplot.tight_layout()
    pyplot.legend(patches, ["Perfect", "Correct", "Incorrect", "Common Error"],
                  loc="lower left",
                  ncol=2)

    pyplot.savefig("plots/grade_pie-{0}.png".format(base))
Exemplo n.º 5
0
def demographics(experiments, font_family=["Arial"], colors=PIE_COLORS, text_size=14, title_size=18, figsize=(16, 9)):

    fig = pyplot.figure(figsize=figsize)

    # Bin and plot ages
    ax = pyplot.subplot(2, 3, 1)
    ax.set_title("Ages", family=font_family, size=title_size)
    ages = experiments["age"]
    age_bins = [0, 0, 0, 0, 0]
    age_bins[0] = len(ages[ages <= 20])
    age_bins[1] = len(ages[(20 < ages) & (ages < 25)])
    age_bins[2] = len(ages[(25 <= ages) & (ages <= 30)])
    age_bins[3] = len(ages[(30 < ages) & (ages <= 35)])
    age_bins[4] = len(ages[35 < ages])

    ax.pie(
        age_bins,
        labels=["$18-20$", "$20-24$", "$25-30$", "$31-35$", "$> 35$"],
        autopct="%1.1f%%",
        shadow=False,
        colors=colors,
    )

    shade_axis(ax, size=text_size)

    # Bin and plot Python experience
    ax = pyplot.subplot(2, 3, 2)
    ax.set_title("Years of\nPython Experience", family=font_family, size=title_size)
    py = experiments["py_years"]
    py_bins = [0, 0, 0, 0, 0]
    py_bins[0] = len(py[py < 0.5])
    py_bins[1] = len(py[(0.5 <= py) & (py <= 1)])
    py_bins[2] = len(py[(1 < py) & (py <= 2)])
    py_bins[3] = len(py[(2 < py) & (py <= 5)])
    py_bins[4] = len(py[5 < py])

    ax.pie(
        py_bins,
        labels=["$< 1/2$", "$1/2-1$", "$1-2$", "$2-5$", "$> 5$"],
        autopct="%1.1f%%",
        shadow=False,
        colors=colors,
    )

    shade_axis(ax, size=text_size)

    # Bin and plot programming experience
    ax = pyplot.subplot(2, 3, 3)
    ax.set_title("Years of\nProgramming Experience", family=font_family, size=title_size)
    prog = experiments["prog_years"]
    prog_bins = [0, 0, 0, 0, 0]
    prog_bins[0] = len(prog[prog < 2])
    prog_bins[1] = len(prog[(2 <= prog) & (prog <= 3)])
    prog_bins[2] = len(prog[(3 < prog) & (prog <= 5)])
    prog_bins[3] = len(prog[(5 < prog) & (prog <= 10)])
    prog_bins[4] = len(prog[10 < prog])

    ax.pie(
        prog_bins,
        labels=["$< 2$", "$2-3$", "$3-5$", "$5-10$", "$> 10$"],
        autopct="%1.1f%%",
        shadow=False,
        colors=colors,
    )

    shade_axis(ax, size=text_size)

    # Bin and plot education
    ax = pyplot.subplot(2, 3, 4)
    ax.set_title("Highest Degree\nReceived", family=font_family, size=title_size)
    degrees = experiments["degree"].value_counts()

    ax.pie(
        degrees.values, labels=[x.capitalize() for x in degrees.keys()], autopct="%1.1f%%", shadow=False, colors=colors
    )

    shade_axis(ax, size=text_size)

    # Bin and plot gender
    ax = pyplot.subplot(2, 3, 5)
    ax.set_title("Gender", family=font_family, size=title_size)
    genders = experiments["gender"].value_counts()

    ax.pie(
        genders.values, labels=[x.capitalize() for x in genders.keys()], autopct="%1.1f%%", shadow=False, colors=colors
    )

    shade_axis(ax, size=text_size)

    # Bin and plot CS major
    ax = pyplot.subplot(2, 3, 6)
    ax.set_title("CS Major", family=font_family, size=title_size)
    cs_majors = experiments["cs_major"].value_counts()

    ax.pie(
        cs_majors.values,
        labels=[x.capitalize() for x in cs_majors.keys()],
        autopct="%1.1f%%",
        shadow=False,
        colors=colors,
    )

    shade_axis(ax, size=text_size)

    fig.tight_layout()
    fig.subplots_adjust(left=0.05, wspace=0.5)

    return fig
Exemplo n.º 6
0
def demographics(experiments,
                 font_family=["Arial"],
                 colors=PIE_COLORS,
                 text_size=14,
                 title_size=18,
                 figsize=(16, 9)):

    fig = pyplot.figure(figsize=figsize)

    # Bin and plot ages
    ax = pyplot.subplot(2, 3, 1)
    ax.set_title("Ages", family=font_family, size=title_size)
    ages = experiments["age"]
    age_bins = [0, 0, 0, 0, 0]
    age_bins[0] = len(ages[ages <= 20])
    age_bins[1] = len(ages[(20 < ages) & (ages < 25)])
    age_bins[2] = len(ages[(25 <= ages) & (ages <= 30)])
    age_bins[3] = len(ages[(30 < ages) & (ages <= 35)])
    age_bins[4] = len(ages[35 < ages])

    ax.pie(age_bins,
           labels=["$18-20$", "$20-24$", "$25-30$", "$31-35$", "$> 35$"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot Python experience
    ax = pyplot.subplot(2, 3, 2)
    ax.set_title("Years of\nPython Experience",
                 family=font_family,
                 size=title_size)
    py = experiments["py_years"]
    py_bins = [0, 0, 0, 0, 0]
    py_bins[0] = len(py[py < .5])
    py_bins[1] = len(py[(.5 <= py) & (py <= 1)])
    py_bins[2] = len(py[(1 < py) & (py <= 2)])
    py_bins[3] = len(py[(2 < py) & (py <= 5)])
    py_bins[4] = len(py[5 < py])

    ax.pie(py_bins,
           labels=["$< 1/2$", "$1/2-1$", "$1-2$", "$2-5$", "$> 5$"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot programming experience
    ax = pyplot.subplot(2, 3, 3)
    ax.set_title("Years of\nProgramming Experience",
                 family=font_family,
                 size=title_size)
    prog = experiments["prog_years"]
    prog_bins = [0, 0, 0, 0, 0]
    prog_bins[0] = len(prog[prog < 2])
    prog_bins[1] = len(prog[(2 <= prog) & (prog <= 3)])
    prog_bins[2] = len(prog[(3 < prog) & (prog <= 5)])
    prog_bins[3] = len(prog[(5 < prog) & (prog <= 10)])
    prog_bins[4] = len(prog[10 < prog])

    ax.pie(prog_bins,
           labels=["$< 2$", "$2-3$", "$3-5$", "$5-10$", "$> 10$"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot education
    ax = pyplot.subplot(2, 3, 4)
    ax.set_title("Highest Degree\nReceived",
                 family=font_family,
                 size=title_size)
    degrees = experiments["degree"].value_counts()

    ax.pie(degrees.values,
           labels=[x.capitalize() for x in degrees.keys()],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot gender
    ax = pyplot.subplot(2, 3, 5)
    ax.set_title("Gender", family=font_family, size=title_size)
    genders = experiments["gender"].value_counts()

    ax.pie(genders.values,
           labels=[x.capitalize() for x in genders.keys()],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot CS major
    ax = pyplot.subplot(2, 3, 6)
    ax.set_title("CS Major", family=font_family, size=title_size)
    cs_majors = experiments["cs_major"].value_counts()

    ax.pie(cs_majors.values,
           labels=[x.capitalize() for x in cs_majors.keys()],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    fig.tight_layout()
    fig.subplots_adjust(left=0.05, wspace=0.5)

    return fig
Exemplo n.º 7
0
def demographics(exp_df):
    """Pie chart of participant demographics"""
    pyplot.figure(figsize=(12, 12))

    # Bin and plot ages
    ax = pyplot.subplot(2, 2, 1)
    ax.set_title("Ages", family=font_family, size=title_size)
    ages = exp_df["age"]
    age_bins = [0, 0, 0, 0, 0]
    age_bins[0] = len(ages[ages <= 20])
    age_bins[1] = len(ages[(20 < ages) & (ages < 25)])
    age_bins[2] = len(ages[(25 <= ages) & (ages <= 30)])
    age_bins[3] = len(ages[(30 < ages) & (ages <= 35)])
    age_bins[4] = len(ages[35 < ages])

    ax.pie(
        age_bins, labels=["18-20", "20-24", "25-30", "31-35", "> 35"], autopct="%1.1f%%", shadow=False, colors=colors
    )

    shade_axis(ax, size=text_size)

    # Bin and plot Python experience
    ax = pyplot.subplot(2, 2, 2)
    ax.set_title("Years of\nPython Experience", family=font_family, size=title_size)
    py = exp_df["py_years"]
    py_bins = [0, 0, 0, 0, 0]
    py_bins[0] = len(py[py < 0.5])
    py_bins[1] = len(py[(0.5 <= py) & (py <= 1)])
    py_bins[2] = len(py[(1 < py) & (py <= 2)])
    py_bins[3] = len(py[(2 < py) & (py <= 5)])
    py_bins[4] = len(py[5 < py])

    ax.pie(py_bins, labels=["< 1/2", "1/2-1", "1-2", "2-5", "> 5"], autopct="%1.1f%%", shadow=False, colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot programming experience
    ax = pyplot.subplot(2, 2, 3)
    ax.set_title("Years of\nProgramming Experience", family=font_family, size=title_size)
    prog = exp_df["prog_years"]
    prog_bins = [0, 0, 0, 0, 0]
    prog_bins[0] = len(prog[prog < 2])
    prog_bins[1] = len(prog[(2 <= prog) & (prog <= 3)])
    prog_bins[2] = len(prog[(3 < prog) & (prog <= 5)])
    prog_bins[3] = len(prog[(5 < prog) & (prog <= 10)])
    prog_bins[4] = len(prog[10 < prog])

    ax.pie(prog_bins, labels=["< 2", "2-3", "3-5", "5-10", "> 10"], autopct="%1.1f%%", shadow=False, colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot education
    ax = pyplot.subplot(2, 2, 4)
    ax.set_title("Highest Degree\nReceived", family=font_family, size=title_size)
    degrees = exp_df["degree"].value_counts()

    ax.pie(
        degrees.values, labels=[x.capitalize() for x in degrees.keys()], autopct="%1.1f%%", shadow=False, colors=colors
    )

    shade_axis(ax, size=text_size)

    pyplot.tight_layout()
    pyplot.savefig("plots/demographics.png")
Exemplo n.º 8
0
def demographics(exp_df):
    """Pie chart of participant demographics"""
    pyplot.figure(figsize=(12, 12))

    # Bin and plot ages
    ax = pyplot.subplot(2, 2, 1)
    ax.set_title("Ages", family=font_family, size=title_size)
    ages = exp_df["age"]
    age_bins = [0, 0, 0, 0, 0]
    age_bins[0] = len(ages[ages <= 20])
    age_bins[1] = len(ages[(20 < ages) & (ages < 25)])
    age_bins[2] = len(ages[(25 <= ages) & (ages <= 30)])
    age_bins[3] = len(ages[(30 < ages) & (ages <= 35)])
    age_bins[4] = len(ages[35 < ages])

    ax.pie(age_bins,
           labels=["18-20", "20-24", "25-30", "31-35", "> 35"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot Python experience
    ax = pyplot.subplot(2, 2, 2)
    ax.set_title("Years of\nPython Experience",
                 family=font_family,
                 size=title_size)
    py = exp_df["py_years"]
    py_bins = [0, 0, 0, 0, 0]
    py_bins[0] = len(py[py < .5])
    py_bins[1] = len(py[(.5 <= py) & (py <= 1)])
    py_bins[2] = len(py[(1 < py) & (py <= 2)])
    py_bins[3] = len(py[(2 < py) & (py <= 5)])
    py_bins[4] = len(py[5 < py])

    ax.pie(py_bins,
           labels=["< 1/2", "1/2-1", "1-2", "2-5", "> 5"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot programming experience
    ax = pyplot.subplot(2, 2, 3)
    ax.set_title("Years of\nProgramming Experience",
                 family=font_family,
                 size=title_size)
    prog = exp_df["prog_years"]
    prog_bins = [0, 0, 0, 0, 0]
    prog_bins[0] = len(prog[prog < 2])
    prog_bins[1] = len(prog[(2 <= prog) & (prog <= 3)])
    prog_bins[2] = len(prog[(3 < prog) & (prog <= 5)])
    prog_bins[3] = len(prog[(5 < prog) & (prog <= 10)])
    prog_bins[4] = len(prog[10 < prog])

    ax.pie(prog_bins,
           labels=["< 2", "2-3", "3-5", "5-10", "> 10"],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    # Bin and plot education
    ax = pyplot.subplot(2, 2, 4)
    ax.set_title("Highest Degree\nReceived",
                 family=font_family,
                 size=title_size)
    degrees = exp_df["degree"].value_counts()

    ax.pie(degrees.values,
           labels=[x.capitalize() for x in degrees.keys()],
           autopct="%1.1f%%",
           shadow=False,
           colors=colors)

    shade_axis(ax, size=text_size)

    pyplot.tight_layout()
    pyplot.savefig("plots/demographics.png")