本文整理汇总了Python中bokeh.embed.components方法的典型用法代码示例。如果您正苦于以下问题:Python embed.components方法的具体用法?Python embed.components怎么用?Python embed.components使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.embed
的用法示例。
在下文中一共展示了embed.components方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chart
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def chart(num_bars):
"""Creates a bar chart with the desired number of bars in a chart."""
if num_bars <= 0:
num_bars = 1
data = {"days": [], "bugs": [], "costs": []}
for i in range(1, num_bars + 1):
data['days'].append(i)
data['bugs'].append(random.randint(1,100))
data['costs'].append(random.uniform(1.00, 1000.00))
hover = create_hover_tool()
plot = create_bar_chart(data, "Bugs found per day", "days",
"bugs", hover)
script, div = components(plot)
return template(TEMPLATE_STRING, bars_count=num_bars,
the_div=div, the_script=script)
示例2: chart
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def chart(bars_count):
if bars_count <= 0:
bars_count = 1
data = {"days": [], "bugs": [], "costs": []}
for i in range(1, bars_count + 1):
data['days'].append(i)
data['bugs'].append(random.randint(1,100))
data['costs'].append(random.uniform(1.00, 1000.00))
hover = create_hover_tool()
plot = create_bar_chart(data, "Bugs found per day", "days",
"bugs", hover)
script, div = components(plot)
return render_template("chart.html", bars_count=bars_count,
the_div=div, the_script=script)
示例3: calculation_view
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def calculation_view(request, calculation_id):
calculation = Calculation.objects.get(pk=calculation_id)
data = get_globals()
data['calculation'] = calculation
data['stdout'] = ''
data['stderr'] = ''
if os.path.exists(os.path.join(calculation.path, 'stdout.txt')):
with open(os.path.join(calculation.path, 'stdout.txt')) as fr:
data['stdout'] = fr.read()
if os.path.exists(os.path.join(calculation.path, 'stderr.txt')):
with open(os.path.join(calculation.path, 'stderr.txt')) as fr:
data['stderr'] = fr.read()
try:
data['incar'] = ''.join(calculation.read_incar())
except VaspError:
data['incar'] = 'Could not read INCAR'
if not calculation.dos is None:
script, div = components(calculation.dos.bokeh_plot)
data['dos'] = script
data['dosdiv'] = div
return render_to_response('analysis/calculation.html',
data, RequestContext(request))
示例4: index
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def index():
# Create layout
c_map = climate_map()
ts = timeseries()
l = legend()
t = title()
map_legend = hplot(c_map, l)
layout = vplot(t, map_legend, ts)
plot_resources = RESOURCES.render(
js_raw=INLINE.js_raw,
css_raw=INLINE.css_raw,
js_files=INLINE.js_files,
css_files=INLINE.css_files,
)
script, div = components(layout, INLINE)
html = flask.render_template(
'embed.html',
plot_script=script,
plot_div=div,
plot_resources=plot_resources,
)
return encode_utf8(html)
示例5: test_bokeh
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def test_bokeh():
from bokeh.plotting import figure
import ipyvolume.bokeh
x, y, z = np.random.random((3, 100))
p3.figure()
scatter = p3.scatter(x, y, z)
tools = "wheel_zoom,box_zoom,box_select,lasso_select,help,reset,"
p = figure(title="E Lz space", tools=tools, width=500, height=500)
r = p.circle(x, y, color="navy", alpha=0.2)
ipyvolume.bokeh.link_data_source_selection_to_widget(r.data_source, scatter, 'selected')
from bokeh.resources import CDN
from bokeh.embed import components
script, div = components(p)
template_options = dict(
extra_script_head=script + CDN.render_js() + CDN.render_css(),
body_pre="<h2>Do selections in 2d (bokeh)<h2>" + div + "<h2>And see the selection in ipyvolume<h2>",
)
ipyvolume.embed.embed_html(
"tmp/bokeh.html", [p3.gcc(), ipyvolume.bokeh.wmh], all_states=True, template_options=template_options
)
示例6: create
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def create(self):
self.source = self.update_source()
max_data = max(max(self.source.data['relevant']), max(self.source.data['crawled']))
xdr = Range1d(start=0, end=max_data)
p = figure(plot_width=400, plot_height=400,
title="Domains Sorted by %s" % self.sort, x_range = xdr,
y_range = FactorRange(factors=self.source.data['domain']),
tools='reset, resize, save')
p.rect(y='domain', x='crawled_half', width="crawled", height=0.75,
color=DARK_GRAY, source =self.source, legend="crawled")
p.rect(y='domain', x='relevant_half', width="relevant", height=0.75,
color=GREEN, source =self.source, legend="relevant")
p.ygrid.grid_line_color = None
p.xgrid.grid_line_color = '#8592A0'
p.axis.major_label_text_font_size = "8pt"
script, div = components(p)
if os.path.exists(self.crawled_data) and os.path.exists(self.relevant_data):
return (script, div)
示例7: index
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def index():
# Create the plot
plot = create_figure()
# tag here means the tag to reference to the new bokeh chart, saved as a js file
js, plot_tag = components(plot, CDN, "/Users/brendantham/Desktop/FYP/Flask/static/plots")
# TODO:
# 1) fix URLS
# 2) figure out where to store the js files for future load use
# with open('/Users/brendantham/Desktop/FYP/Flask/static/plots/plot1.js', 'w') as f:
# f.write(js)
return render_template("index.html", script1 = js, plot1 = plot_tag)
# With debug=True, Flask server will auto-reload
# when there are code changes
示例8: plot_bokeh
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def plot_bokeh(self, return_components=False):
""" If components is specified, will return script, div-tuple """
if not self.data:
self._preprocess()
result = self.result if return_components else {}
for budget, dataframe in self.data.items():
plot = self._plot_budget(dataframe)
if return_components:
result[budget] = {'bokeh': components(plot)}
else:
result[budget] = plot
# If only one budget, we don't need an extra tab...
if len(result) == 1:
result = list(result.values())[0]
return result
示例9: get_html
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def get_html(self, d=None, tooltip=None):
bokeh_components = components(self.plot())
if d is not None:
if self.num_quantiles == 1 or self.use_timeslider: # No need for "Static" with one plot / time slider activated
d[self.name] = {
"bokeh" : bokeh_components,
"tooltip": self.__doc__,
}
else:
d[self.name] = {
"tooltip": self.__doc__,
"Interactive" : {"bokeh": (bokeh_components)},
}
if all([True for p in self.cfp_paths if os.path.exists(p)]): # If the plots were actually generated
d[self.name]["Static"] = {"figure": self.cfp_paths}
else:
d[self.name]["Static"] = {
"else": "This plot is missing. Maybe it was not generated? "
"Check if you installed selenium and phantomjs "
"correctly to activate bokeh-exports. "
"(https://automl.github.io/CAVE/stable/faq.html)"}
return bokeh_components
示例10: get_html
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def get_html(self, d=None, tooltip=None):
self.run()
if len(self.result) == 1 and None in self.result:
self.logger.debug("Detected None-key, abstracting away...")
self.result = self.result[None]
if d is not None:
d[self.name] = OrderedDict()
script, div = "", ""
for b, t in self.result.items():
s_, d_ = components(t) if b == 'bokeh' else components(t['bokeh'])
script += s_
div += d_
if d is not None:
if b == 'bokeh':
d[self.name] = {
"bokeh": (s_, d_),
"tooltip": self.__doc__,
}
else:
d[self.name][b] = {
"bokeh": (s_, d_),
"tooltip": self.__doc__,
}
return script, div
示例11: embedded_html
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def embedded_html(fig, resources="CDN"):
"""Returns an html string that contains all neccessary CSS&JS files,
together with the div containing the Bokeh plot. As input, a figure fig
is expected."""
html_embedded = ""
if resources == "CDN":
js_css_resources = get_bokeh_resources()
html_embedded += js_css_resources
elif resources == "raw":
raise NotImplementedError("<resources> = raw has to be implemented by Thomas!")
elif resources == None:
pass
else:
raise ValueError("<resources> only accept 'CDN', 'raw' or None.")
# Add plot script and div
script, div = components(fig)
html_embedded += "\n\n" + div + "\n\n" + script
return html_embedded
示例12: getHTML
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def getHTML(self, params):
ticker = params['ticker']
if ticker == 'empty':
ticker = params['custom_ticker'].upper()
df = self.getData(params) # get data
try:
bokeh_plot = plotting.line(
df.index, df['Close'], color='#1c2980',
legend="Close", x_axis_type="datetime", title=ticker
)
except AttributeError:
bokeh_plot = plotting.figure(x_axis_type='datetime', title=ticker)
bokeh_plot.line(df.index, df['Close'], color='#1c2980', legend="Close")
bokeh_plot.line(df.index, df['High'], color='#80641c', legend="High")
bokeh_plot.line(df.index, df['Low'], color='#80321c', legend="Low")
script, div = components(bokeh_plot, CDN)
html = "%s\n%s" % (script, div)
return html
示例13: add_plot
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def add_plot(stockStat, conf):
p_list = []
logging.info("############################", type(conf["dic"]))
# 循环 多个line 信息。
for key, val in enumerate(conf["dic"]):
logging.info(key)
logging.info(val)
p1 = figure(width=1000, height=150, x_axis_type="datetime")
# add renderers
stockStat["date"] = pd.to_datetime(stockStat.index.values)
# ["volume","volume_delta"]
# 设置20个颜色循环,显示0 2 4 6 号序列。
p1.line(stockStat["date"], stockStat[val], color=Category20[20][key * 2])
# Set date format for x axis 格式化。
p1.xaxis.formatter = DatetimeTickFormatter(
hours=["%Y-%m-%d"], days=["%Y-%m-%d"],
months=["%Y-%m-%d"], years=["%Y-%m-%d"])
# p1.xaxis.major_label_orientation = radians(30) #可以旋转一个角度。
p_list.append([p1])
gp = gridplot(p_list)
script, div = components(gp)
return {
"script": script,
"div": div,
"title": conf["title"],
"desc": conf["desc"]
}
示例14: bokehplot
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def bokehplot():
figure = make_plot()
fig_script, fig_div = components(figure)
return render_template(
"bokeh.html.j2",
fig_script=fig_script,
fig_div=fig_div,
bkversion=bokeh.__version__,
)
示例15: pvalue_plot
# 需要导入模块: from bokeh import embed [as 别名]
# 或者: from bokeh.embed import components [as 别名]
def pvalue_plot( date, pvalues_lower, pvalues_upper ):
plot = figure(x_axis_type = "datetime", plot_height=250, plot_width=600)
plot.line(date, pvalues_lower, legend='Lower', line_color='green')
plot.line(date, pvalues_upper, legend='Upper', line_color='red')
plot.legend.orientation = "top_left"
plot.title = '-log(P Values)'
script, div = components(plot, CDN)
return { 'script': script, 'div': div }