对于 Holoview 和 Bokeh 的循环概览,主题未生效
For looping overview with Holoview and Bokeh, theme is not taking effect
尝试使用 Holoview 和 Bokeh 在循环中创建多个绘图。主题在第一个单一情节案例中生效,但在第二个案例中被忽略。我做错了什么?
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import dim, opts
from bokeh.palettes import Spectral6
import configparser
import hvplot.pandas
import json
from bokeh.plotting import figure, show
hv.extension('bokeh')
idx = pd.date_range("2021-01-01", periods=10, freq="H")
df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD'), index=idx)
# First Case
dist_opts = opts.Curve(height=300, xrotation=45, fontsize={'title': 10, 'labels': 10, 'xticks': 6, 'yticks': 8}, title = f"Title " )
hv.renderer('bokeh').theme = 'dark_minimal'
hline = hv.HLine(0)
hline_opts = opts.HLine(line_width=2, line_color='indianred', line_dash='dotted', line_alpha=0.9)
hdf = df.iloc[:,1].hvplot(legend=False,responsive=True)
overlay = hdf* hline
overlay.opts(dist_opts, hline_opts)
overlay
# Second Case
def set_plot(df):
hline = hv.HLine(0)
hline_opts = opts.HLine(line_width=2, line_color='indianred', line_dash='dotted', line_alpha=0.9)
hdf = df.hvplot(legend=False,responsive=True)
overlay = hdf* hline
overlay.opts(dist_opts, hline_opts)
return overlay
def show_plots(df):
# hv.renderer('bokeh').theme = 'dark_minimal'
plots_list = []
for i in range(0,len(df.columns)):
print(i)
this_plot = set_plot(df.iloc[:,i])
plots_list.append(this_plot)
plot = hv.Layout(plots_list).cols(2)
show(hv.render(plot))
show_plots(df)
谢谢
Holoviews 无需调用 show
即可自动显示对象,这似乎与某些事情有关。如果您将代码更改为简单的 return 布局,而不是在其上调用 show
,主题就会出现:
def show_plots(df):
hv.renderer('bokeh').theme = 'dark_minimal'
plots_list = []
for i in range(0,len(df.columns)):
print(i)
this_plot = set_plot(df.iloc[:,i])
plots_list.append(this_plot)
return hv.Layout(plots_list).cols(2)
我不确定这是不是故意的。您可能会考虑在 Holoviews 问题跟踪器上提出问题以进行澄清。这可能是不可避免的,因为 show
是一个 Bokeh 函数,并且对 Holoviews 中设置的主题一无所知(这可以解释为什么调用 show
不考虑 HV 设置)。
尝试使用 Holoview 和 Bokeh 在循环中创建多个绘图。主题在第一个单一情节案例中生效,但在第二个案例中被忽略。我做错了什么?
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import dim, opts
from bokeh.palettes import Spectral6
import configparser
import hvplot.pandas
import json
from bokeh.plotting import figure, show
hv.extension('bokeh')
idx = pd.date_range("2021-01-01", periods=10, freq="H")
df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD'), index=idx)
# First Case
dist_opts = opts.Curve(height=300, xrotation=45, fontsize={'title': 10, 'labels': 10, 'xticks': 6, 'yticks': 8}, title = f"Title " )
hv.renderer('bokeh').theme = 'dark_minimal'
hline = hv.HLine(0)
hline_opts = opts.HLine(line_width=2, line_color='indianred', line_dash='dotted', line_alpha=0.9)
hdf = df.iloc[:,1].hvplot(legend=False,responsive=True)
overlay = hdf* hline
overlay.opts(dist_opts, hline_opts)
overlay
# Second Case
def set_plot(df):
hline = hv.HLine(0)
hline_opts = opts.HLine(line_width=2, line_color='indianred', line_dash='dotted', line_alpha=0.9)
hdf = df.hvplot(legend=False,responsive=True)
overlay = hdf* hline
overlay.opts(dist_opts, hline_opts)
return overlay
def show_plots(df):
# hv.renderer('bokeh').theme = 'dark_minimal'
plots_list = []
for i in range(0,len(df.columns)):
print(i)
this_plot = set_plot(df.iloc[:,i])
plots_list.append(this_plot)
plot = hv.Layout(plots_list).cols(2)
show(hv.render(plot))
show_plots(df)
谢谢
Holoviews 无需调用 show
即可自动显示对象,这似乎与某些事情有关。如果您将代码更改为简单的 return 布局,而不是在其上调用 show
,主题就会出现:
def show_plots(df):
hv.renderer('bokeh').theme = 'dark_minimal'
plots_list = []
for i in range(0,len(df.columns)):
print(i)
this_plot = set_plot(df.iloc[:,i])
plots_list.append(this_plot)
return hv.Layout(plots_list).cols(2)
我不确定这是不是故意的。您可能会考虑在 Holoviews 问题跟踪器上提出问题以进行澄清。这可能是不可避免的,因为 show
是一个 Bokeh 函数,并且对 Holoviews 中设置的主题一无所知(这可以解释为什么调用 show
不考虑 HV 设置)。