python 使用Holoviews,如何设置标题?

6vl6ewon  于 2024-01-05  发布在  Python
关注(0)|答案(3)|浏览(146)

我一直在尝试使用Holoviews和Bokeh时设置标题。我将3个图相互叠加。代码看起来像这样:

  1. %%opts Curve [width=900 height=400 show_grid=True tools=['hover'] finalize_hooks=[apply_formatter]]
  2. %%opts Curve (color=Cycle('Category20'))
  3. %%opts Overlay [ legend_position='bottom' ] Curve (muted_alpha=0.5 muted_color='black' )
  4. actual_curve = hv.Curve(df_reg_test, 'date', 'y', label='Actual')
  5. existing_curve = hv.Curve(df_reg_test, 'date', 'Forecast Calls', label='Existing Forecast')
  6. xgb_curve = hv.Curve(df_reg_test, 'date', 'xgb_pred', label='New Forecast')
  7. actual_curve * existing_curve * xgb_curve

字符串
图看起来像这样:

正如您所看到的,各个曲线的标签在图例中显示得很好,但在图的顶部没有标题。
如何手动设置标题?

i86rm4rw

i86rm4rw1#

另一种将一般标题添加到叠加的方法是使用:

opts.Overlay(title ='Overlay的新标题')

以下是在Holoview Overlay图上设置标题的示例:

  1. # import libraries
  2. import numpy as np
  3. import holoviews as hv
  4. from holoviews import opts
  5. hv.extension('bokeh')
  6. # create some sample data
  7. data1 = np.random.normal(size=[50, 2])
  8. data2 = np.random.normal(size=[50, 2])
  9. # create your overlay plot
  10. all_plots = hv.Scatter(data1, label='data1') * hv.Scatter(data2, label='data2')
  11. # add your title to your overlay with opts.Overlay()
  12. all_plots.opts(opts.Overlay(title='New title for Overlay'))

字符串

生成的图看起来像这样:


的数据

展开查看全部
pdkcd3nj

pdkcd3nj2#

我发现我可以在覆盖选项中添加一个title_format=“我的新标题”选项:

  1. %%opts Curve [width=900 height=400 show_grid=True tools=['hover'] finalize_hooks=[apply_formatter]]
  2. %%opts Curve (color=Cycle('Category20'))
  3. %%opts Overlay [ legend_position='bottom' title_format="my new title"] Curve (muted_alpha=0.5 muted_color='black' )
  4. actual_curve = hv.Curve(df_reg_test, 'date', 'y', label='Actual')
  5. existing_curve = hv.Curve(df_reg_test, 'date', 'Forecast Calls', label='Existing Forecast')
  6. xgb_curve = hv.Curve(df_reg_test, 'date', 'xgb_pred', label='New Forecast')
  7. actual_curve * existing_curve * xgb_curve

字符串
现在我的情节有一个标题:


的数据

展开查看全部
ukxgm1gy

ukxgm1gy3#

虽然在像您这样的情况下,当多个图叠加时可能会产生误导,但您也可以使用opts(title)设置单个hv.Curve的标题: 

  1. actual_curve = hv.Curve(
  2. ).opts(
  3. title = 'Some cool title'
  4. )

字符串

相关问题