hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Method for captioning plots `df.hvplot.caption()` or `hvplot.caption()`

Open ahuang11 opened this issue 6 months ago • 3 comments

I'm creating a explanatory visualization and it'd be awesome if hvplot had a caption method so you can do something like

df.hvplot.bar("date", "arr") * df_sum.hvplot.caption("Total ARR {arr} from {ini_date} to {end_date}")

Or even df.hvplot.bar("date", "arr", caption=f"Total ARR {arr} from {ini_date} to {end_date}", caption_loc="bottom_left")

ahuang11 avatar Aug 26 '25 20:08 ahuang11

Can you please define a bit more what you would expect to see on the plot when setting caption? I'd appreciate it if you could provide links to HoloViews to see what feature we'd need to expose in hvPlot, and if not already supported in HoloViews, to Bokeh and Matplotlib docs.

maximlt avatar Aug 27 '25 08:08 maximlt

Oops, missed this in the pile of GitHub notifications about locked issues.

Perhaps this should be first implemented in HoloViews, e.g. hv.Title(loc=...) https://docs.bokeh.org/en/latest/docs/user_guide/basic/annotations.html#labels

That does this in Bokeh:

from bokeh.models import Title
from bokeh.plotting import figure, show

p = figure(title="Left Title", title_location="left",
           width=300, height=300)

p.scatter([1, 2], [3, 4])

# add extra titles with add_layout(...)
p.add_layout(Title(text="A caption about life and such\nLong caption", align="left"), place="below")

show(p)
Image

And this in matplotlib (focus only on the bottom left caption):

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(3, 3))

# main title on the left (like title_location="left")
ax.set_title("Left Title", loc="left")

# scatter plot
ax.scatter([1, 2], [3, 4])

# add caption below the plot
fig.text(
    0.1, -0.05,  # (x, y) in figure coordinates, can be tuned
    "A caption about life and such\nLong caption",
    ha="left", va="top"
)

plt.show()

Image

ahuang11 avatar Sep 29 '25 23:09 ahuang11

Yes these notifications are wild! I think @hoxbro has a bot or something to clear them automatically. He has a bot or script for everything ;)

Ok thanks I understand better what you mean:

  • As far as hvPlot is concerned, I don't really think that should be a plot method but simply exposed as an option caption=....
  • Let's open an issue for HoloViews (I'd prefer if this was a plot option rather than a element, not a fan of having to deal with overlays for simply adding a caption)

maximlt avatar Sep 30 '25 07:09 maximlt