Skip to content

Commit

Permalink
cleanup plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinerum committed Jul 17, 2023
1 parent f522fd2 commit 5b192d9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 21 deletions.
11 changes: 7 additions & 4 deletions varats/varats/plots/interactions_change_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def plot(self, view_mode: bool) -> None:
"interactions_diff": [],
"project": []
})
plt.rcParams.update({"text.usetex": True, "font.family": "Helvetica"})
for case_study in case_studys:
cs_data = lines_per_interactions_squashed(case_study, True)
cs_data["interactions_diff"] = cs_data.groupby(
Expand All @@ -49,20 +50,22 @@ def plot(self, view_mode: bool) -> None:

df = data_sub.to_frame().reset_index()
df["interactions_diff"] = df["interactions_diff"].apply(lambda x: x + 1)
df["project"] = df["project"].apply(lambda x: f"\\textsc{{{x}}}")
axis = sns.violinplot(
data=df,
y="interactions_diff",
x="project",
bw=0.15,
scale="width",
inner=None
inner=None,
cut=0,
)
axis.plot(range(len(case_studys)), [1 for _ in case_studys], "--k")

axis.set_ylabel("")
axis.yaxis.set_visible(False)
axis.set_ylabel("Change in $\\frac{interactions}{lines}$")
axis.set_xlabel("Project")
plt.gcf().set_size_inches(10, 5)
plt.yscale("asinh")
axis.set_yticklabels([])


class InteractionChangeAuthorDistribution(

Check failure on line 71 in varats/varats/plots/interactions_change_distribution.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/plots/interactions_change_distribution.py#L71 <115>

Missing class docstring (missing-class-docstring)
Raw output
varats/varats/plots/interactions_change_distribution.py:71:0: C0115: Missing class docstring (missing-class-docstring)
Expand Down
41 changes: 34 additions & 7 deletions varats/varats/plots/revision_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,39 @@ def __init__(self, plot_config: PlotConfig, **kwargs: tp.Any):
super().__init__(plot_config, **kwargs)

def plot(self, view_mode: bool) -> None:
case_studys: tp.List[CaseStudy] = self.plot_kwargs["case_study"]
data = self.plot_kwargs["data"]
axis = sns.violinplot(
full_data = self.plot_kwargs["data"].copy()
full_data["project"] = "All"
data["project"] = data["project"].apply(lambda x: f"\\textsc{{{x}}}")
plt.rcParams.update({"text.usetex": True, "font.family": "Helvetica"})
grid = sns.JointGrid(
x="project",
y="impacted_commits",
data=data,
)

sns.violinplot(
ax=grid.ax_joint,
data=data,
y="impacted_commits",
x="project",
bw=0.15,
scale="width",
inner=None
inner=None,
cut=0
)
axis.plot(range(len(case_studys)), [0 for _ in case_studys], "--k")
sns.kdeplot(
ax=grid.ax_marg_y,
data=full_data,
y="impacted_commits",
bw=0.15,
cut=0,
fill=True,
)
grid.set_axis_labels("Projects", "Impact", fontsize=14)
plt.gcf().set_size_inches(10, 5)
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)


class RevisionImpactDistributionAll(
Expand All @@ -168,7 +190,8 @@ def __init__(self, plot_config: PlotConfig, **kwargs: tp.Any):
def plot(self, view_mode: bool) -> None:
data = self.plot_kwargs["data"]
data.drop(columns=["project"], inplace=True)
sns.violinplot(data=data, y="impacted_commits", bw=0.15)
sns.violinplot(data=data, y="impacted_commits", bw=0.15, cut=0)
plt.ylabel("Impact", fontsize=10)


class RevisionImpactScatterInteractions(
Expand Down Expand Up @@ -223,13 +246,17 @@ def plot(self, view_mode: bool) -> None:
)
)
data = apply_tukeys_fence(data, "line_change", 3)
multivariate_grid(
data["project"] = data["project"].apply(lambda x: f"\\textsc{{{x}}}")

plt.rcParams.update({"text.usetex": True, "font.family": "Helvetica"})
grid = multivariate_grid(
data,
"impacted_commits",
"line_change",
"project",
alpha=0.3,
)
grid.set_axis_labels("Impact", "Changed Lines", fontsize=10)
plt.gcf().set_size_inches(10, 5)
ymax = data["line_change"].max()
plt.ylim(-0.001, ymax + 0.01)

Expand Down
18 changes: 8 additions & 10 deletions varats/varats/plots/surviving_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def name(self) -> str:
def plot(self, view_mode: bool) -> None:
"""Plot the evolution of a single commit."""
_, axis = plt.subplots(1, 1)
plt.rcParams.update({"text.usetex": True, "font.family": "Helvetica"})
case_study = self.plot_kwargs['case_study']
lines: DataFrame = get_lines_per_commit_long(case_study, False)

Expand Down Expand Up @@ -278,19 +279,16 @@ def plot(self, view_mode: bool) -> None:
ax = axis.twinx()
x_axis = range(len(data))
ax.scatter(x_axis, data['lines'], color="green")
ax.set_ylabel("Lines", color="g")
ax.set_ylabel("Lines", color="g", fontsize=14)
axis.scatter(x_axis, data['interactions'], color="orange")
axis.set_ylabel("Interactions", color="orange")
axis.set_ylabel("Interactions", color="orange", fontsize=14)
axis.tick_params(axis="y", labelsize=14)
ax.set_ylim(ymin=0)
axis.set_ylim(ymin=0)
lines_legend = mpatches.Patch(color='green', label="Lines")
interactions_legend = mpatches.Patch(
color="orange", label='Interactions'
)
plt.legend(handles=[lines_legend, interactions_legend])
plt.ticklabel_format(axis='x', useOffset=False)
axis.set_xticklabels(data.index.map(cmap.short_time_id), rotation=90)
axis.tick_params(axis="x", labelrotation=90)
axis.set_xlabel("Revisions", fontsize=14)
axis.set_xticklabels([])
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)


class HeatMapPlot(Plot, plot_name=None):
Expand Down
21 changes: 21 additions & 0 deletions varats/varats/tables/revision_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd

from varats.mapping.commit_map import CommitMap, get_commit_map
from varats.paper.case_study import CaseStudy
from varats.plots.revision_impact import impact_data
from varats.project.project_util import get_primary_project_source
from varats.table.table import Table
Expand Down Expand Up @@ -110,6 +111,16 @@ def tabulate(self, table_format: TableFormat, wrap_table: bool) -> str:
)


class RandomCommitsTable(Table, table_name="volatile_commits"):

Check failure on line 114 in varats/varats/tables/revision_impact.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tables/revision_impact.py#L114 <115>

Missing class docstring (missing-class-docstring)
Raw output
varats/varats/tables/revision_impact.py:114:0: C0115: Missing class docstring (missing-class-docstring)

def tabulate(self, table_format: TableFormat, wrap_table: bool) -> str:
case_studys: tp.List[CaseStudy] = self.table_kwargs["case_study"]
data = impact_data(case_studys)
df = data.sample(n=100)
df.to_csv("random-commits.csv")
return dataframe_to_table(df, table_format, wrap_table=wrap_table)


class LineImpactDistribution(Table, table_name="line_impact_distribution"):
"""Table showing high impact revisions."""

Expand Down Expand Up @@ -241,3 +252,13 @@ def generate(self) -> tp.List['varats.table.table.Table']:
ImpactDistribution(self.table_config, **self.table_kwargs),
LineImpactDistribution(self.table_config, **self.table_kwargs)
]


class RandomCommitsGenerator(

Check failure on line 257 in varats/varats/tables/revision_impact.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tables/revision_impact.py#L257 <115>

Missing class docstring (missing-class-docstring)
Raw output
varats/varats/tables/revision_impact.py:257:0: C0115: Missing class docstring (missing-class-docstring)
TableGenerator,
generator_name="random-commits",
options=[REQUIRE_MULTI_CASE_STUDY]
):

def generate(self) -> tp.List['varats.table.table.Table']:
return [RandomCommitsTable(self.table_config, **self.table_kwargs)]
1 change: 1 addition & 0 deletions varats/varats/tables/surviving_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def commmit_data(commit: FullCommitHash,
commmit_data(row["base_hash"], row["interactions_diff"])
)
df = pd.DataFrame(volatile_commits)
df.to_csv("volatile_commits.csv")
return dataframe_to_table(df, table_format, wrap_table=wrap_table)


Expand Down

0 comments on commit 5b192d9

Please sign in to comment.