猿问

使用 Holoviews,如何设置标题?

我一直在尝试在使用 Holoviews 和 Bokeh 时设置标题。我正在相互叠加 3 个地块。代码如下所示:


%%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

情节是这样的:

如您所见,各个曲线的标签在图例中显示得很好,但我在图的顶部没有标题。

如何手动设置标题?


开满天机
浏览 307回答 2
2回答

慕婉清6462132

另一种为叠加添加一般标题的方法是使用:opts.Overlay(title='New title for Overlay')以下是在 Holoview 叠加图上设置标题的示例:# import librariesimport numpy as npimport holoviews as hvfrom holoviews import optshv.extension('bokeh')# create some sample datadata1 = np.random.normal(size=[50, 2])data2 = np.random.normal(size=[50, 2])# create your overlay plotall_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'))结果图将如下所示:

largeQ

我发现我可以在叠加选项中添加一个 title_format="my new title" 选项:%%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现在我的情节有一个标题:
随时随地看视频慕课网APP

相关分类

Python
我要回答