Skip to content

Commit

Permalink
Fix Plotting of Data with Just a Single Series/Group (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fthaler authored Jun 26, 2024
1 parent 3067f01 commit 95a8faf
Showing 1 changed file with 18 additions and 13 deletions.
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

0 comments on commit 95a8faf

Please sign in to comment.