5

I have been trying to set a title when using Holoviews and Bokeh. I'm overlaying 3 plots on each other. The code looks like this:

%%opts Curve [width=900 height=400  show_grid=True tools=['hover'] finalize_hooks=[apply_formatter]]
%%opts Curve (color=Cycle('Category20'))
%%opts Overlay [ legend_position='bottom' ] Curve (muted_alpha=0.5 muted_color='black' )

actual_curve = hv.Curve(df_reg_test, 'date', 'y', label='Actual')
existing_curve = hv.Curve(df_reg_test, 'date', 'Forecast Calls', label='Existing Forecast')
xgb_curve = hv.Curve(df_reg_test, 'date', 'xgb_pred', label='New Forecast')

actual_curve * existing_curve * xgb_curve

The plot looks like this: Holoview Plot

As you can see, the labels of the individual curves show up great in the legend, but I get no title at the top of the plot.

How can I manually just set a title?

Bob Swain
  • 3,052
  • 3
  • 17
  • 28

2 Answers2

3

Another way of adding a general title to your Overlay is by using:
opts.Overlay(title='New title for Overlay')

Here's an example of setting a title on your Holoview Overlay plot:

# import libraries
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

# create some sample data
data1 = np.random.normal(size=[50, 2])
data2 = np.random.normal(size=[50, 2])

# create your overlay plot
all_plots = hv.Scatter(data1, label='data1') * hv.Scatter(data2, label='data2')

# add your title to your overlay with opts.Overlay()
all_plots.opts(opts.Overlay(title='New title for Overlay'))

The resulting plot will look like this:

New title on Overlay Holoviews graph

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
1

I figured out that I can add a title_format="my new title" option in the overlay opts:

%%opts Curve [width=900 height=400  show_grid=True tools=['hover'] finalize_hooks=[apply_formatter]]
%%opts Curve (color=Cycle('Category20'))
%%opts Overlay [ legend_position='bottom' title_format="my new title"] Curve (muted_alpha=0.5 muted_color='black' )

actual_curve = hv.Curve(df_reg_test, 'date', 'y', label='Actual')
existing_curve = hv.Curve(df_reg_test, 'date', 'Forecast Calls', label='Existing Forecast')
xgb_curve = hv.Curve(df_reg_test, 'date', 'xgb_pred', label='New Forecast')

actual_curve * existing_curve * xgb_curve

Now my plot has a title:

Holoviews Plot with Title

Bob Swain
  • 3,052
  • 3
  • 17
  • 28
  • Can we set a general title to a layout of images stacked side by side apart from the individual title image? – Scope Oct 12 '20 at 09:18