简体   繁体   English

Arviz 和 Bokeh:尝试使用后端 kwargs 更改 plot 的标题

[英]Arviz and Bokeh: Trying to change the title of the plot using backend kwargs

I am trying to change the title of the plot I'm creating with Arviz.我正在尝试更改我正在使用 Arviz 创建的 plot 的标题。 Usually I have done this using the backend_kwargs but it doesn't seem to work for certain plots: in this case the plot_density .通常我已经使用backend_kwargs完成了此操作,但它似乎不适用于某些地块:在本例中为plot_density

This is the code i'm using:这是我正在使用的代码:

kwg = dict(title="prior_1", height=500)
plot = az.plot_density(
                   data_m[0], 
                   group='posterior', 
                   var_names='switchpoint', 
                   backend='bokeh',
                   shade=.5, 
                   backend_kwargs=kwg
                   )

It recognises the height change in the kwargs so its not like its not picking up on them being there.它识别出kwargs的高度变化,所以它不像没有注意到它们在那里。

I have also tried other variations such as plot_title= and it will produce an error specifying it needs to be title=我还尝试了其他变体,例如plot_title= ,它会产生一个错误,指定它需要是title=

ArviZ initializes Bokeh Plot instances using the alias figure . ArviZ 使用别名figure初始化 Bokeh Plot实例。 As you can see reading the docs on Plot , title is a valid argument.正如您在阅读Plot上的文档时看到的那样, title是一个有效的参数。 For several reasons however, ArviZ does not use this argument when creating the plots, it sets the title afterwards.然而,出于多种原因,ArviZ 在创建绘图时不使用此参数,而是在之后设置标题。 Thus, your argument is being recognized and used only to be overwritten.因此,您的论点被识别并仅用于被覆盖。

plot_density sets the title of each plot to the variable name and, if multidimensional, its coordinates. plot_density将每个 plot 的标题设置为变量名称,如果是多维的,则设置其坐标。 Moreover, in addition to multiple variables (each of which can be multidimensional), it also supports plotting multiple models (thus different InferenceData objects) at the same time.此外,除了多个变量(每个变量都可以是多维的)之外,它还支持同时绘制多个模型(因此不同的InferenceData对象)。 You can use the argument data_labels to set the legend labels.您可以使用参数data_labels来设置图例标签。 An example of this can be seen in ArviZ's example gallery , you can even click on the legend to hide models.ArviZ 的示例库中可以看到一个示例,您甚至可以单击图例来隐藏模型。

Therefore, to achieve the desired result, you have to manually modify the title after calling plot_density , which can be done with a couple extra lines.因此,为了达到预期的效果,您必须在调用plot_density后手动修改标题,这可以通过几行额外的代码来完成。 You have to call plot_density with show=False so that the figure can be modified afterwards.您必须使用show=False调用plot_density以便之后可以修改该图形。 Then the title can be edited from the elements stored in the array returned by plot_density .然后可以从plot_density返回的数组中存储的元素编辑标题。

kwg = dict(height=500)
axes = az.plot_density(
    data_m[0],
    group="posterior",
    var_names="switchpoint",
    backend="bokeh",
    shade=0.5,
    backend_kwargs=kwg,
    show=False
)
axes[0,0].title.text = "prior_1"
az.plots.backends.show_layout(axes)

If you had multiple plots with several multidimensional variables you would have to edit the title for each one by looping over the array.如果您有多个带有多个多维变量的图,则必须通过遍历数组来编辑每个图的标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM