nschloe/perfplot

Support for custom plot title

zoj613 opened this issue · 5 comments

Is it possible to add a custom title at the top of a plot? It would be very useful to add a little bit of information about the plot in some instances (like a description explaining the setup).

Sure, use plt.title after perfplot.plot.

@nschloe It doesn't work. I call o = perfplot.bench() then plt.title(), then o.show() or o.save(), the plots do not have the custom plot.

It only works if I use plt.figure().suptitle()

The following works:

import numpy
import matplotlib.pyplot as plt
import perfplot

perfplot.plot(
    setup=lambda n: numpy.random.rand(n),  # or setup=numpy.random.rand
    kernels=[
        lambda a: numpy.c_[a, a],
        lambda a: numpy.stack([a, a]).T,
        lambda a: numpy.vstack([a, a]).T,
        lambda a: numpy.column_stack([a, a]),
        lambda a: numpy.concatenate([a[:, None], a[:, None]], axis=1),
    ],
    labels=["c_", "stack", "vstack", "column_stack", "concat"],
    n_range=[2 ** k for k in range(5)],
    xlabel="len(a)",
)

plt.title("custom title")
plt.show()

Not sure what's different in your setup, but good that you figured it out.

The following works:

import numpy
import matplotlib.pyplot as plt
import perfplot

perfplot.plot(
    setup=lambda n: numpy.random.rand(n),  # or setup=numpy.random.rand
    kernels=[
        lambda a: numpy.c_[a, a],
        lambda a: numpy.stack([a, a]).T,
        lambda a: numpy.vstack([a, a]).T,
        lambda a: numpy.column_stack([a, a]),
        lambda a: numpy.concatenate([a[:, None], a[:, None]], axis=1),
    ],
    labels=["c_", "stack", "vstack", "column_stack", "concat"],
    n_range=[2 ** k for k in range(5)],
    xlabel="len(a)",
)

plt.title("custom title")
plt.show()

Not sure what's different in your setup, but good that you figured it out.

I was using perfplot.bench() not the plot function. Then afterwards called title. In that setup it worked when I switched to using the figure's suptitle