本文整理汇总了Python中bokeh.resources.INLINE类的典型用法代码示例。如果您正苦于以下问题:Python INLINE类的具体用法?Python INLINE怎么用?Python INLINE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了INLINE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index(request):
plot = figure(responsive=True, tools=[],
plot_width=500, plot_height=250,
x_range=(-180, 180), y_range=(-90, 90))
plot.toolbar_location = None
plot.axis.visible = None
source = AjaxDataSource(method='GET',
data_url='http://localhost:8000/view2d/data/',
polling_interval=1000)
source.data = dict(x=[], y=[]) # Workaround to initialize the plot
img = load_image("static/images/earth.png")
plot.image_rgba(image=[img], x=[-180], y=[-90], dw=[360], dh=[180])
plot.cross(source=source, x='x', y='y',
size=22, line_width=4, color='Orange') # CLU1
script, div = components(plot, INLINE)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
context = {
'bokeh_script' : script,
'bokeh_div' : div,
'js_resources' : js_resources,
'css_resources' : css_resources
}
return render(request, 'view2d/index.html', context)
示例2: polynomial
def polynomial():
""" Very simple embedding of a polynomial chart
"""
# Grab the inputs arguments from the URL
args = flask.request.args
# Get all the form arguments in the url with defaults
color = getitem(args, 'color', 'Black')
_from = int(getitem(args, '_from', 0))
to = int(getitem(args, 'to', 10))
# Create a polynomial line graph with those arguments
x = list(range(_from, to + 1))
fig = figure(title="Polynomial")
fig.line(x, [i ** 2 for i in x], color=colors[color], line_width=2)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig)
html = flask.render_template(
'embed.html',
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
color=color,
_from=_from,
to=to
)
return encode_utf8(html)
示例3: data_retrieval
def data_retrieval():
conn = lite.connect('/Users/shanekenny/PycharmProjects/WiFinder/app/website/WiFinderDBv02.db')
with conn:
df = pd.read_sql_query("SELECT W.Log_Count, W.Time, W.Hour, W.Datetime, R.RoomID, R.Capacity, C.ClassID, C.Module, C.Reg_Students, O.Occupancy, O.OccID FROM WIFI_LOGS W JOIN CLASS C ON W.ClassID = C.ClassID JOIN ROOM R ON C.Room = R.RoomID JOIN OCCUPANCY O ON C.ClassID = O.ClassID WHERE R.RoomID = 'B002' AND W.Datetime = '2015-11-12' GROUP BY W.LogID;", conn)
df['Time'] = df['Time'].apply(pd.to_datetime)
p = figure(width=800, height=250, x_axis_type="datetime", )
p.extra_y_ranges = {"foo": Range1d(start=0, end=1)}
p.line(df['Time'], df['Log_Count'], color='red',legend='Log Count')
p.line(df['Time'], df['Reg_Students'], color='green',legend='Registered Students')
p.line(df['Time'], df['Capacity'], color='blue', legend='Capacity')
p.line(df['Time'], df['Occupancy']*100, color='orange', legend='Occupancy')
p.add_layout(LinearAxis(y_range_name="foo"), 'left')
p2 = figure(width=800, height=250, x_axis_type="datetime", x_range=p.x_range,)
p2.line(df['Time'], df['Log_Count'], color='red', legend='Log Count')
r= gridplot([[p, p2]], toolbar_location=None)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(r)
return flask.render_template(
'explore.html',
script=script,
div=div,
js_resources=js_resources,
css_resources=css_resources,)
示例4: second_stock
def second_stock():
n = app_stock.vars['name']
ss = "WIKI/" + n + ".4"
mydata = quandl.get(ss, encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date', trim_start="2016-05-05", trim_end="2016-06-05", returns = "numpy", authtoken="ZemsPswo-xM16GFxuKP2")
mydata = pd.DataFrame(mydata)
#mydata['Date'] = mydata['Date'].astype('datetime64[ns]')
x = mydata['Date']
y = mydata['Close']
p = figure(title="Stock close price", x_axis_label='Date', y_axis_label='close price', plot_height = 300, plot_width = 550)
p.line(x, y, legend="Price in USD", line_width=3, color = "#2222aa")
# Configure resources to include BokehJS inline in the document.
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components
script, div = components(p, INLINE)
html = flask.render_template(
'stockgraph.html',
ticker = app_stock.vars['name'],
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
)
return encode_utf8(html)
示例5: showind
def showind():
c0 = request.args['country0']
c1 = request.args['country1']
c2 = request.args['country2']
c3 = request.args['country3']
c4 = request.args['country4']
countries = [c0, c1, c2, c3, c4]
i0 = request.args['indicator']
indicator = [i0]
performance = get_indicator(countries,indicator)
chartind = plot_ind(performance)
script,div = components(chartind)
return render_template('showind.html',
js_resources=INLINE.render_js(),
css_resources=INLINE.render_css(),
script=script,
div=div)
示例6: showbusscore
def showbusscore():
c0 = request.args['country0']
c1 = request.args['country1']
c2 = request.args['country2']
c3 = request.args['country3']
c4 = request.args['country4']
countries = [c0, c1, c2, c3, c4]
i0 = "IC.BUS.EASE.XQ"
indicators = [i0]
dataframes = create_dataframes(countries,indicators)
score = get_mean(dataframes)
chartsco = plot_score(score)
script,div = components(chartsco)
return render_template('showscore.html',
js_resources=INLINE.render_js(),
css_resources=INLINE.render_css(),
script=script,
div=div)
示例7: dataframe_to_linegraph
def dataframe_to_linegraph(dataframe, show_columns, title='graph'):
'''Convert a dataframe to a bokeh line graph'''
thisplot = figure(
tools="pan,box_zoom,reset,save",
title=title,
x_axis_type="datetime",
x_axis_label='Month',
y_axis_label='Count',
plot_width=1200,
)
yvals = [x for x in dataframe.index.tolist()]
idx = 0
for col, show in show_columns:
if not show:
continue
width = 2
try:
color = Paired[12][idx]
except IndexError:
color = Paired[12][-1]
kwargs = {
'legend': col,
'line_width': width,
'line_color': color
}
idx += 1
xvals = dataframe[col].tolist()
line = thisplot.line(
yvals,
xvals,
**kwargs
)
thisplot.add_tools(
HoverTool(
renderers=[line],
tooltips=[
('Name', col),
('Color', '<span class="bk-tooltip-color-block" '
'style="background-color:{}"> </span>'.
format(kwargs['line_color'])),
('count', "@y{int}"),
]
)
)
thisplot.legend.location = "top_left"
plot_script, plot_div = components(thisplot)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
return (plot_script, plot_div, js_resources, css_resources)
示例8: save
def save(fig):
'''
Saves bokeh plots to HTML in ./Bokeh_plots
'''
## Set up directory for the plot files
plots_dir = os.path.join('.','Bokeh_plots')
if not os.path.exists(plots_dir):
os.makedirs(plots_dir)
filename = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')+'.html'
figfile = os.path.join(plots_dir, filename)
## Save and show figure
from jinja2 import Template
from bokeh.embed import components
from bokeh.resources import INLINE
plots = {'fig':fig}
script, div = components(plots)
template = Template('''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bokeh Scatter Plots</title>
{{ js_resources }}
{{ css_resources }}
{{ script }}
<style>
.embed-wrapper {
width: 50%;
height: 400px;
margin: auto;
}
</style>
</head>
<body>
{% for key in div.keys() %}
<div class="embed-wrapper">
{{ div[key] }}
</div>
{% endfor %}
</body>
</html>
''')
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
bokeh_html = template.render(js_resources=js_resources,
css_resources=css_resources,
script=script,
div=div)
with open(figfile, 'w') as f:
f.write(bokeh_html)
示例9: app_parse
def app_parse():
ticker_input = app.vars['ticker']
# ticker_input = raw_input('Please enter a stock ticker code (e.g., AAPL): ')
quandl_url = 'https://www.quandl.com/api/v3/datasets/WIKI/'
api_key = '_Dvc2yU_qTfyYtTzsqFd'
csv_ext = '.csv'
json_ext = '.json'
input_url = quandl_url + ticker_input + json_ext
input_csv = quandl_url + ticker_input + csv_ext
r = requests.get(input_url)
data = json.loads(r.text)
pd_data = pd.read_csv(input_csv,parse_dates=['Date'])
x = data["dataset"]["data"]
data_rows = len(x)
data_rows_good = np.zeros(data_rows)
start_date = datetime.now().date() + timedelta(-30)
booleans = []
for date_row in range(0,len(pd_data.Date)):
# ticker_date = datetime.strptime(pd_data.Date[date_row],'%Y-%m-%d').date()
ticker_date = pd_data.Date[date_row].date()
if start_date < ticker_date:
booleans.append(True)
else:
booleans.append(False)
closing_price = pd_data.Close[booleans]
# output_file("datetime.html")
# create a new plot with a datetime axis type
p = figure(width=500, height=500, x_axis_type="datetime")
p.line(pd_data.Date[booleans], pd_data.Close[booleans], color='red', alpha=0.5)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(p, INLINE)
html = flask.render_template(
'datetime.html',
ticker = app_stock.vars['name'],
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
)
return encode_utf8(html)
示例10: polynomial
def polynomial():
""" Very simple embedding of a polynomial chart
"""
# connect to google spreadsheet and get sheet
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('oauth-keyfile.json', scopes=scope)
gc = gspread.authorize(credentials)
responses = gc.open("Homework Histogram (Responses)")
responses = responses.worksheet("Form Responses 1")
# create plot html elements
data = pd.DataFrame(responses.get_all_records())
# hist = Histogram(data, values='Question 1')
# create a list of plots
scripts = []
divs = []
for question in ['Question 1', 'Question 2']:
hist = Histogram(data, values=question)
script, div = components(hist, INLINE)
scripts.append(script)
divs.append(div)
# Configure resources to include BokehJS inline in the document.
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
# script, div = components(hist, INLINE)
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components
html = flask.render_template(
'embed.html',
scripts = scripts,
divs=divs,
js_resources=js_resources,
css_resources=css_resources,
)
return encode_utf8(html)
示例11: index
def index():
if request.method == 'GET':
return render_template('index.html')
else:
app.vars['Company_Name'] = request.form['ticker']
if not app.vars['Company_Name']:
return render_template('error.html')
app.vars['features'] = request.form.getlist('features')
Company_Name=app.vars['Company_Name']
API_url='https://www.quandl.com/api/v3/datasets/WIKI/%s.csv?api_key=a5-JLQBhNfxLnwxfXoUE' % Company_Name
r = requests.get(API_url)
if r.status_code == 404:
return render_template('error.html')
data = pd.read_csv(API_url,parse_dates=['Date'])
Colors=["blue","green","yellow","red"]
Color_index=0
target_data=data.ix[:,['Open','Adj. Open','Close','Adj. Close']]
p=figure(x_axis_type="datetime")
p.xaxis.axis_label = 'Date'
p.title = 'Data from Quandle WIKI set'
if 'Close' in app.vars['features']:
p.line(x=data['Date'],y=target_data['Close'],legend="%s:Close" % Company_Name, line_color=Colors[Color_index])
Color_index = Color_index +1
if 'Adj. Close' in app.vars['features']:
p.line(x=data['Date'],y=target_data['Adj. Close'],legend="%s:Adj. Close" % Company_Name, line_color=Colors[Color_index])
Color_index = Color_index +1
if 'Open' in app.vars['features']:
p.line(x=data['Date'],y=target_data['Open'],legend="%s:Open" % Company_Name, line_color=Colors[Color_index])
Color_index = Color_index +1
if 'Adj. Open' in app.vars['features']:
p.line(x=data['Date'],y=target_data['Adj. Open'],legend="%s:Adj. Open" % Company_Name, line_color=Colors[Color_index])
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(p, INLINE)
html = flask.render_template(
'embed.html',
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
Company_Name= Company_Name
)
return encode_utf8(html)
示例12: index
def index():
if request.method == 'POST':
# Get the entered keywords
keywords = request.form["keywords"]
#keywords = [keyword.strip() for keyword in keywords.split(',') if len(keyword) > 0]
keywords = [keyword.strip() for keyword in keywords.split(',') if len(keyword.strip()) > 0]
keywords = keywords[:len(COLORS)] # prevent too many keywords
# Get the location data
user_location = (request.form['latitude'], request.form['longitude'])
logger.info('{} | {}'.format(user_location, keywords))
fig = make_fig(keywords)
# Build the bokeh plot resources
# https://github.com/bokeh/bokeh/tree/master/examples/embed/simple
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig, INLINE)
# Get recent comments matching the keywords
recent_comments = get_matching_comments_2(keywords, user_location)
# special case if no keywords entered - show 'All' comment counts
if not keywords:
keywords = ['All']
# Build the web page
html = render_template(
'index.html',
keywords = ', '.join(keyword.title() for keyword in keywords),
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
jobs=recent_comments,
)
return html
return render_template('index.html')
示例13: plot
def plot(content, data=[]):
x = list(range(0, 100 + 1))
fig = figure(title="Polynomial")
print(dir(fig))
#fig.line(x, [i ** 2 for i in x], line_width=2)
#fig.hbar(data['requested_by_name'], data['usage'])
p=Bar(data, 'requested_by_name', values='usage')
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(p)
html = render_template(
'overview.html',
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
content=content,
)
return encode_utf8(html)
示例14: bokeh_bild
def bokeh_bild(range=4800):
data = bk_plot_timeline(
LoadFromSQL(
range,
app.config['DATABASE_LOCATION'],
'VS1_GT1',
'VS1_GT3',
'VS1_GT2',
'VS1_Setpoint'
)
)
print(data)
plot_script, plot_div = components(data, INLINE)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
return render_template(
'bild.html',
script=plot_script,
div=plot_div,
js_resources=js_resources,
css_resources=css_resources)
示例15: polynomial
def polynomial():
""" Very simple embedding of a polynomial chart
"""
# Grab the inputs arguments from the URL
# This is automated by the button
args = flask.request.args
# Get all the form arguments in the url with defaults
color = colors[getitem(args, 'color', 'Black')]
_from = int(getitem(args, '_from', 0))
to = int(getitem(args, 'to', 10))
# Create a polynomial line graph
x = list(range(_from, to + 1))
fig = figure(title="Polynomial")
fig.line(x, [i ** 2 for i in x], color=color, line_width=2)
# Configure resources to include BokehJS inline in the document.
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
# For more details see:
# http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components
script, div = components(fig, INLINE)
html = flask.render_template(
'embed.html',
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources,
color=color,
_from=_from,
to=to
)
return encode_utf8(html)