本文整理汇总了Python中bokeh.objects.Plot类的典型用法代码示例。如果您正苦于以下问题:Python Plot类的具体用法?Python Plot怎么用?Python Plot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_plot
def make_plot(name, glyph):
glyph_renderer = GlyphRenderer(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=glyph)
pantool = PanTool(dataranges=[xdr, ydr], dimensions=["width", "height"])
zoomtool = ZoomTool(dataranges=[xdr, ydr], dimensions=("width", "height"))
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0)
ygrid = Grid(plot=plot, dimension=1)
plot.renderers.append(glyph_renderer)
plot.tools = [pantool, zoomtool]
try:
sess = session.PlotServerSession(username="defaultuser", serverloc="http://localhost:5006", userapikey="nokey")
except requests.exceptions.ConnectionError as e:
print e
print "\nThis example requires the plot server. Please make sure plot server is running, via 'python runserver.py' in the bokeh root directory.\n"
sys.exit()
sess.add(plot, glyph_renderer, xaxis, yaxis, xgrid, ygrid, source, xdr, ydr, pantool, zoomtool)
sess.use_doc(name)
sess.plotcontext.children.append(plot)
sess.plotcontext._dirty = True
sess.store_all()
示例2: make_plot
def make_plot(source, xname, yname, linecolor, xdr=None, ydr=None):
""" Returns a tuple (plot, [obj1...objN]); the former can be added
to a GridPlot, and the latter is added to the plotcontext.
"""
if xdr is None:
xdr = DataRange1d(sources=[source.columns(xname)])
if ydr is None:
ydr = DataRange1d(sources=[source.columns(yname)])
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source],
border=50)
xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
yaxis = LinearAxis(plot=plot, dimension=1, location="left")
pantool = PanTool(dataranges=[xdr,ydr], dimensions=["width","height"])
zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height"))
renderer = Glyph(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = Line(x=xname, y=yname, linecolor=linecolor),
)
plot.renderers.append(renderer)
plot.tools = [pantool, zoomtool]
return plot, (renderer, xaxis, yaxis, source, xdr, ydr,
pantool, zoomtool)
示例3: make_plot
def make_plot(name, glyph):
glyph_renderer = GlyphRenderer(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = glyph,
)
pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"])
zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height"))
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Rule(plot=plot, dimension=0)
ygrid = Rule(plot=plot, dimension=1)
plot.renderers.append(glyph_renderer)
plot.tools = [pantool,zoomtool]
sess = session.PlotServerSession(
username="defaultuser",
serverloc="http://localhost:5006",
userapikey="nokey"
)
sess.add(plot, glyph_renderer, xaxis, yaxis, xgrid, ygrid, source, xdr, ydr, pantool, zoomtool)
sess.use_doc(name)
sess.store_all()
示例4: make_plot
def make_plot(xname, yname, xax=False, yax=False, text=None):
plot = Plot(
x_range=xdr, y_range=ydr, data_sources=[source], background_fill="#efe8e2",
width=250, height=250, border_fill='white', title="", min_border=2, border_symmetry=None)
if xax:
xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
if yax:
yaxis = LinearAxis(plot=plot, dimension=1, location="left")
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color")
circle_renderer = Glyph(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = circle,
)
plot.renderers.append(circle_renderer)
plot.tools = [pan, zoom]
if text:
text = " ".join(text.split('_'))
text = Text(
x={'field':'xcenter', 'units':'screen'},
y={'field':'ycenter', 'units':'screen'},
text=[text], angle=pi/4, text_font_style="bold", text_baseline="top",
text_color="#ffaaaa", text_alpha=0.7, text_align="center", text_font_size="28pt")
text_renderer = Glyph(
data_source=text_source,
xdata_range = xdr,
ydata_range = ydr,
glyph = text,
)
plot.data_sources.append(text_source)
plot.renderers.append(text_renderer)
return plot
示例5: make_plot
def make_plot(xname, yname, xax=False, yax=False, text=None):
plot = Plot(
x_range=xdr, y_range=ydr, data_sources=[source], background_fill="#ffeedd",
width=250, height=250, border_fill='white', title="", border_symmetry="", min_border=2)
objs = []
if xax:
xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
objs.append(xaxis)
if yax:
yaxis = LinearAxis(plot=plot, dimension=1, location="left")
objs.append(yaxis)
xgrid = Grid(plot=plot, dimension=0)
ygrid = Grid(plot=plot, dimension=1)
circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, radius=2, line_color="color")
circle_renderer = GlyphRenderer(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = circle,
)
plot.renderers.append(circle_renderer)
plot.tools = [pan, zoom]
if text:
text = " ".join(text.split('_'))
text = Text(x=4, y=4, text=text, angle=pi/4, text_font_style="bold", text_baseline="top",
text_color="#ffaaaa", text_alpha=0.2, text_align="center", text_font_size="28pt")
text_renderer = GlyphRenderer(
data_source=source,
xdata_range = xdr,
ydata_range = ydr,
glyph = text,
)
plot.renderers.append(text_renderer)
objs.append(text_renderer)
return plot, objs + [circle_renderer, xgrid, ygrid]
示例6: make_plot
def make_plot(name, glyph):
glyph_renderer = Glyph(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = glyph,
)
pantool = PanTool(dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dimensions=["width", "height"])
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
plot.renderers.append(glyph_renderer)
plot.tools = [pantool, wheelzoomtool]
try:
sess = session.PlotServerSession(
serverloc="http://localhost:5006",
username="defaultuser",
userapikey="nokey")
except requests.exceptions.ConnectionError:
print("ERROR: This example requires the plot server. Please make sure plot server is running, by executing 'bokeh-server'")
sys.exit(1)
sess.use_doc(name)
sess.add_plot(plot)
sess.store_all()
示例7: make_plot
def make_plot():
from numpy import pi, arange, sin, cos
import numpy as np
from bokeh.objects import (
Plot, DataRange1d, LinearAxis,
ColumnDataSource, GlyphRenderer,
PanTool, PreviewSaveTool)
from bokeh.glyphs import Circle
from bokeh import session
x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
z = cos(x)
widths = np.ones_like(x) * 0.02
heights = np.ones_like(x) * 0.2
source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths,
heights=heights))
xdr = DataRange1d(sources=[source.columns("x")])
ydr = DataRange1d(sources=[source.columns("y")])
circle = Circle(x="x", y="y", fill="red", radius=5, line_color="black")
glyph_renderer = GlyphRenderer(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = circle)
pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"])
previewtool = PreviewSaveTool(dataranges=[xdr,ydr], dimensions=("width","height"))
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source],
border= 80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
plot.renderers.append(glyph_renderer)
plot.tools = [pantool, previewtool]
sess = session.PlotServerSession(
username="defaultuser",
serverloc="http://localhost:5006", userapikey="nokey")
sess.use_doc("glyph2")
sess.add(plot, glyph_renderer, xaxis, yaxis, # xgrid, ygrid,
source, xdr, ydr, pantool, previewtool)
sess.plotcontext.children.append(plot)
sess.plotcontext._dirty = True
# not so nice.. but set the model doens't know
# that we appended to children
sess.store_all()
return plot
示例8: sample_gear
def sample_gear():
xdr = Range1d(start=-30, end=30)
ydr = Range1d(start=-30, end=30)
source = ColumnDataSource(data=dict(dummy=[0]))
plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800)
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
glyph = Gear(x=0, y=0, module=5, teeth=8, angle=0, shaft_size=0.2, fill_color=fill_color[2], line_color=line_color)
plot.add_glyph(source, glyph)
return plot
示例9: pyramid_plot
def pyramid_plot(self):
from bokeh.objects import (Plot, DataRange1d, LinearAxis, Grid,
Legend, SingleIntervalTicker)
from bokeh.glyphs import Quad
xdr = DataRange1d(sources=[self.source_pyramid.columns("male"),
self.source_pyramid.columns("female")])
ydr = DataRange1d(sources=[self.source_pyramid.columns("groups")])
self.plot = Plot(title="Widgets", x_range=xdr, y_range=ydr,
plot_width=600, plot_height=600)
xaxis = LinearAxis()
self.plot.add_layout(xaxis, 'below')
yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=5))
self.plot.add_layout(yaxis, 'left')
self.plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
self.plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
male_quad = Quad(left="male", right=0, bottom="groups", top="shifted",
fill_color="#3B8686")
male_quad_glyph = self.plot.add_glyph(self.source_pyramid, male_quad)
female_quad = Quad(left=0, right="female", bottom="groups", top="shifted",
fill_color="#CFF09E")
female_quad_glyph = self.plot.add_glyph(self.source_pyramid, female_quad)
self.plot.add_layout(Legend(legends=dict(Male=[male_quad_glyph],
Female=[female_quad_glyph])))
示例10: classical_gear
def classical_gear(module, large_teeth, small_teeth):
xdr = Range1d(start=-300, end=150)
ydr = Range1d(start=-100, end=100)
source = ColumnDataSource(data=dict(dummy=[0]))
plot = Plot(
title=None,
x_range=xdr, y_range=ydr,
plot_width=800, plot_height=800
)
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
radius = pitch_radius(module, large_teeth)
angle = 0
glyph = Gear(
x=-radius, y=0,
module=module, teeth=large_teeth, angle=angle,
fill_color=fill_color[0], line_color=line_color
)
plot.add_glyph(source, glyph)
radius = pitch_radius(module, small_teeth)
angle = half_tooth(small_teeth)
glyph = Gear(
x=radius, y=0,
module=module, teeth=small_teeth, angle=angle,
fill_color=fill_color[1], line_color=line_color
)
plot.add_glyph(source, glyph)
return plot
示例11: jobtype_builder
def jobtype_builder():
jtypes = ["Half Time", "Full Time", "Hourly", "Temporary"]
xdr = FactorRange(factors=jtypes)
ydr = DataRange1d(sources=[source_jobtype.columns("data_range")])
plot = Plot(title="Job Type", data_sources=[source_jobtype],
x_range=xdr, y_range=ydr, plot_width=760, plot_height=500)
xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4.0)
yaxis = LinearAxis(plot=plot, dimension=1)
yaxis.major_tick_in = 0
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
quad = Rect(x="jobtypes", y="jobtype_half",
height="count", width=0.9,
fill_color="#33A6A4")
bars = Glyph(data_source=source_jobtype, xdata_range=xdr,
ydata_range=ydr, glyph=quad)
plot.renderers.append(bars)
plot.background_fill = '#686975'
return plot
示例12: weekday_builder
def weekday_builder():
dow = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"]
xdr = FactorRange(factors=dow)
ydr = DataRange1d(sources=[source_dow.columns("data_range")])
plot = Plot(title="Weekday of Job Posting", data_sources=[source_dow],
x_range=xdr, y_range=ydr, plot_width=760, plot_height=500)
xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4.0)
yaxis = LinearAxis(plot=plot, dimension=1)
yaxis.major_tick_in = 0
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
quad = Rect(x="weekday", y="weekday_half",
height="count", width=0.9,
fill_color="#D9301A")
bars = Glyph(data_source=source_dow, xdata_range=xdr,
ydata_range=ydr, glyph=quad)
plot.renderers.append(bars)
plot.background_fill = '#686975'
return plot
示例13: make_tab
def make_tab(title, glyph):
plot = Plot(title=title, x_range=xdr, y_range=ydr)
plot.add_glyph(source, glyph)
xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')
plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
tab = Panel(child=plot, title=title)
return tab
示例14: make_plot
def make_plot(name, glyph):
glyph_renderer = Glyph(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = glyph,
)
pantool = PanTool(dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dimensions=["width", "height"])
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
plot.renderers.append(glyph_renderer)
plot.tools = [pantool, wheelzoomtool]
document.add(plot)
session.store_document(document)
示例15: epicyclic_gear
def epicyclic_gear(module, sun_teeth, planet_teeth):
xdr = Range1d(start=-150, end=150)
ydr = Range1d(start=-150, end=150)
source = ColumnDataSource(data=dict(dummy=[0]))
plot = Plot(
title=None,
x_range=xdr, y_range=ydr,
plot_width=800, plot_height=800
)
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
annulus_teeth = sun_teeth + 2*planet_teeth
glyph = Gear(
x=0, y=0,
module=module, teeth=annulus_teeth, angle=0,
fill_color=fill_color[0], line_color=line_color, internal=True
)
plot.add_glyph(source, glyph)
glyph = Gear(
x=0, y=0,
module=module, teeth=sun_teeth, angle=0,
fill_color=fill_color[2], line_color=line_color
)
plot.add_glyph(source, glyph)
sun_radius = pitch_radius(module, sun_teeth)
planet_radius = pitch_radius(module, planet_teeth)
radius = sun_radius + planet_radius
angle = half_tooth(planet_teeth)
for i, j in [(+1, 0), (0, +1), (-1, 0), (0, -1)]:
glyph = Gear(
x=radius*i, y=radius*j,
module=module, teeth=planet_teeth, angle=angle,
fill_color=fill_color[1], line_color=line_color
)
plot.add_glyph(source, glyph)
return plot