Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Plotting of Data with Just a Single Series/Group #29

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions stencil_benchmarks/scripts/sbench_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def plot(
output,
dpi,
):
"""Plot output of sbench.
"""
"""Plot output of sbench."""
import cycler
from matplotlib import pyplot as plt
from matplotlib import ticker
Expand Down Expand Up @@ -215,29 +214,35 @@ def plot(
pattern, repl = regex[1:-1].split(splitter, 1)
regexes.append((re.compile(pattern), repl))

for index, row in df.iterrows():
def plot_data(index, row):
x = np.arange(len(row.index)) if uniform else row.index
y = row.values / relative_to if relative_to else row.values
if isinstance(index, tuple):
label = ", ".join(
f"{name}={value}" for name, value in zip(df.index.names, index)
)
else:
label = str(index)
label = (
", ".join(f"{name}={value}" for name, value in zip(df.index.names, index))
if isinstance(index, tuple)
else str(index)
)
for regex, repl in regexes:
label = regex.sub(repl, label)
plt.plot(x, y, label=label)
if uniform:
plt.xticks(x, row.index, rotation=45)
if uniform:
plt.xticks(x, row.index, rotation=45)

if isinstance(df, pd.Series):
plot_data(df.index, df)
plt.xlabel(df.index.name)
else:
for index, row in df.iterrows():
plot_data(index, row)
plt.xlabel(df.columns.name)
plt.legend()

for i, ref in enumerate(reference):
label, value = ref.split("=", 1)
value = float(value)
dashes = (5 * (i + 1) + 3 * i, 3)
plt.axhline(value, color="k", ls=(0, dashes), label=label)

plt.legend()
plt.xlabel(df.columns.name)
plt.ylabel(select)
if ylim:
plt.ylim(ylim)
Expand Down