Skip to content

Commit 76e2836

Browse files
authored
Merge pull request #138 from nschloe/add-title
Add title
2 parents f1a8cfd + e34f875 commit 76e2836

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!--[![PyPi downloads](https://img.shields.io/pypi/dm/perfplot.svg?style=flat-square)](https://pypistats.org/packages/perfplot)-->
1111

12-
[![Discord](https://img.shields.io/static/v1?logo=discord&label=chat&message=on%20discord&color=7289da&style=flat-square)](https://discord.gg/hnTJ5MRX2Y)
12+
[![Discord](https://img.shields.io/static/v1?logo=discord&logoColor=white&label=chat&message=on%20discord&color=7289da&style=flat-square)](https://discord.gg/hnTJ5MRX2Y)
1313

1414
[![gh-actions](https://img.shields.io/github/workflow/status/nschloe/perfplot/ci?style=flat-square)](https://github.com/nschloe/perfplot/actions?query=workflow%3Aci)
1515
[![codecov](https://img.shields.io/codecov/c/github/nschloe/perfplot.svg?style=flat-square)](https://codecov.io/gh/nschloe/perfplot)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = perfplot
3-
version = 0.9.13
3+
version = 0.9.14
44
author = Nico Schlömer
55
author_email = nico.schloemer@gmail.com
66
description = Performance plots for Python code snippets

src/perfplot/_main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ def __init__(
6262
flop,
6363
labels: list[str],
6464
xlabel: str | None,
65+
title: str | None,
6566
):
6667
self.n_range = np.asarray(n_range)
6768
self.timings_s = timings_s
6869
self.flop = flop
6970
self.labels = labels
7071
self.xlabel = xlabel
72+
self.title = title
7173

7274
def plot( # noqa: C901
7375
self,
@@ -136,6 +138,8 @@ def plot( # noqa: C901
136138

137139
if self.xlabel:
138140
plt.xlabel(self.xlabel)
141+
if self.title:
142+
plt.title(self.title)
139143
if relative_to is not None and not logy:
140144
plt.gca().set_ylim(bottom=0)
141145

@@ -257,7 +261,10 @@ def __next__(self):
257261
if not is_equal:
258262
raise PerfplotError(
259263
"Equality check failure. "
260-
+ f"({self.labels[0]}, {self.labels[k]})"
264+
+ f"{self.labels[0]}:\n"
265+
+ f"{reference}:\n\n"
266+
+ f"{self.labels[k]}:\n"
267+
+ f"{val}:\n"
261268
)
262269

263270
# First try with one repetition only.
@@ -449,6 +456,7 @@ def bench(
449456
flops: Callable | None = None,
450457
labels: list[str] | None = None,
451458
xlabel: str | None = None,
459+
title: str | None = None,
452460
target_time_per_measurement: float = 1.0,
453461
max_time: float | None = None,
454462
equality_check: Callable | None = np.allclose,
@@ -504,7 +512,7 @@ def callback():
504512
timings_s = timings_s[:i]
505513
n_range = n_range[:i]
506514

507-
return PerfplotData(n_range, timings_s.T, flop, labels, xlabel)
515+
return PerfplotData(n_range, timings_s.T, flop, labels, xlabel, title)
508516

509517

510518
# For backward compatibility:

tests/test_perfplot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def test_automatic_scale(exp_unit, time_ns, time_unit):
9191
timings_s=timings,
9292
labels=["."], # Suppress no handle error # TODO fix this
9393
xlabel="",
94+
title="",
9495
flop=None,
9596
)
9697
# Has the correct unit been applied to the y_label?

0 commit comments

Comments
 (0)