예제 #1
0
파일: downloads.py 프로젝트: salilb/bokeh
 def make_downloads_plot(self, source):
     xdr = DataRange1d(sources=[source.columns("dates")])
     ydr = DataRange1d(sources=[source.columns("downloads")])
     title = "%s downloads" % self.modelform.installer
     plot = Plot(title=title,
                 data_sources=[source],
                 x_range=xdr,
                 y_range=ydr,
                 width=600,
                 height=400)
     line = Line(x="dates", y="downloads", line_color="blue")
     line_glyph = Glyph(data_source=source,
                        xdata_range=xdr,
                        ydata_range=ydr,
                        glyph=line)
     plot.renderers.append(line_glyph)
     circle = Circle(x="dates", y="downloads", fill_color="red")
     circle_glyph = Glyph(data_source=source,
                          xdata_range=xdr,
                          ydata_range=ydr,
                          glyph=circle)
     plot.renderers.append(circle_glyph)
     hover = HoverTool(plot=plot, tooltips=dict(downloads="@downloads"))
     plot.tools.append(hover)
     xformatter = DatetimeTickFormatter(formats=dict(months=["%b %Y"]))
     yformatter = BasicTickFormatter(precision=None, use_scientific=False)
     xaxis = DatetimeAxis(plot=plot, dimension=0, formatter=xformatter)
     yaxis = LinearAxis(plot=plot, dimension=1, formatter=yformatter)
     xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
     ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
     return plot
예제 #2
0
def make_plot():
    xdr = DataRange1d(sources=[source.columns("dates")])
    ydr = DataRange1d(sources=[source.columns("downloads")])

    plot = Plot(title="Product downloads",
                x_range=xdr,
                y_range=ydr,
                plot_width=400,
                plot_height=400)

    line = Line(x="dates", y="downloads", line_color="blue")
    plot.add_glyph(source, line)

    circle = Circle(x="dates", y="downloads", fill_color="red")
    plot.add_glyph(source, circle)

    xaxis = DatetimeAxis()
    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))

    plot.add_tools(HoverTool(tooltips=dict(downloads="@downloads")))

    return plot, source
예제 #3
0
def make_plot():
    source = ColumnDataSource(
        dict(
            dates=[date(2014, 3, i) for i in [1, 2, 3, 4, 5]],
            downloads=[100, 27, 54, 64, 75],
        ))
    xdr = DataRange1d(sources=[source.columns("dates")])
    ydr = DataRange1d(sources=[source.columns("downloads")])
    plot = Plot(title="Product downloads",
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=400,
                height=400)
    line = Line(x="dates", y="downloads", line_color="blue")
    line_glyph = Glyph(data_source=source,
                       xdata_range=xdr,
                       ydata_range=ydr,
                       glyph=line)
    plot.renderers.append(line_glyph)
    circle = Circle(x="dates", y="downloads", fill_color="red")
    circle_glyph = Glyph(data_source=source,
                         xdata_range=xdr,
                         ydata_range=ydr,
                         glyph=circle)
    plot.renderers.append(circle_glyph)
    hover = HoverTool(plot=plot, tooltips=dict(downloads="@downloads"))
    plot.tools.append(hover)
    xaxis = DatetimeAxis(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)
    return plot, source
예제 #4
0
def large_plot():
    source = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1]))

    xdr = Range1d(start=0, end=1)
    xdr.tags.append("foo")
    xdr.tags.append("bar")

    ydr = Range1d(start=10, end=20)
    ydr.tags.append("foo")

    plot = Plot(x_range=xdr, y_range=ydr)

    ydr2 = Range1d(start=0, end=100)
    plot.extra_y_ranges = {"liny": ydr2}

    circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black")
    plot.add_glyph(source, circle, name="mycircle")

    line = Line(x="x", y="y")
    plot.add_glyph(source, line, name="myline")

    rect = Rect(x="x", y="y", width=1, height=1, fill_color="green")
    plot.add_glyph(source, rect, name="myrect")

    plot.add_layout(DatetimeAxis(), 'below')
    plot.add_layout(LogAxis(), 'left')
    plot.add_layout(LinearAxis(y_range_name="liny"), 'left')

    plot.add_layout(Grid(dimension=0), 'left')
    plot.add_layout(Grid(dimension=1), 'left')

    plot.add_tools(
        BoxZoomTool(),
        PanTool(),
        PreviewSaveTool(),
        ResetTool(),
        ResizeTool(),
        WheelZoomTool(),
    )

    return plot
예제 #5
0
source = ColumnDataSource(data=dict(x=x, y=y, times=times))

xdr = DataRange1d(sources=[source.columns("times")])
ydr = DataRange1d(sources=[source.columns("y")])

circle = Circle(x="times", y="y", fill_color="red", size=5, line_color="black")

glyph_renderer = Glyph(
    data_source=source,
    xdata_range=xdr,
    ydata_range=ydr,
    glyph=circle,
)

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = DatetimeAxis(plot=plot, dimension=0, location="min")
yaxis = LinearAxis(plot=plot, dimension=1, location="min")

pantool = PanTool(dataranges=[xdr, ydr], dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dataranges=[xdr, ydr],
                              dimensions=("width", "height"))

plot.renderers.append(glyph_renderer)
plot.tools = [pantool, wheelzoomtool]

sess = session.HTMLFileSession("dateaxis.html")
sess.add(plot, recursive=True)
sess.plotcontext.children.append(plot)
sess.save(js="absolute", css="absolute")
sess.dumpjson(file="dateaxis.json")
print("Wrote %s" % sess.filename)
예제 #6
0
파일: daylight.py 프로젝트: tarzzz/bokeh
line2 = Line(x="dates", y="sunsets", line_color="red", line_width=2)
line2_glyph = Glyph(data_source=source,
                    xdata_range=xdr,
                    ydata_range=ydr,
                    glyph=line2)
plot.renderers.append(line2_glyph)

text = Text(x="dates", y="times", text="texts", angle=0, text_align="center")
text_glyph = Glyph(data_source=text_source,
                   xdata_range=xdr,
                   ydata_range=ydr,
                   glyph=text)
plot.renderers.append(text_glyph)

xformatter = DatetimeTickFormatter(formats=dict(months=["%b %Y"]))
xaxis = DatetimeAxis(plot=plot, dimension=0, formatter=xformatter)
yaxis = DatetimeAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)

legend = Legend(plot=plot,
                legends={
                    "sunrise": [line1_glyph],
                    "sunset": [line2_glyph]
                })
plot.renderers.append(legend)

doc = Document()
doc.add(plot)

if __name__ == "__main__":
예제 #7
0
plot.add_glyph(patch1_source, patch1)

patch2 = Patch(x="dates", y="times", fill_color="orange", fill_alpha=0.8)
plot.add_glyph(patch2_source, patch2)

line1 = Line(x="dates", y="sunrises", line_color="yellow", line_width=2)
line1_glyph = plot.add_glyph(source, line1)

line2 = Line(x="dates", y="sunsets", line_color="red", line_width=2)
line2_glyph = plot.add_glyph(source, line2)

text = Text(x="dates", y="times", text="texts", angle=0, text_align="center")
plot.add_glyph(text_source, text)

xformatter = DatetimeTickFormatter(formats=dict(months=["%b %Y"]))
xaxis = DatetimeAxis(formatter=xformatter)
plot.add_layout(xaxis, 'below')

yaxis = DatetimeAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

legend = Legend(legends=[("sunrise", [line1_glyph]), ("sunset", [line2_glyph])])
plot.add_layout(legend)

doc = Document()
doc.add(plot)

if __name__ == "__main__":
예제 #8
0
y = sin(x)

# Create an array of times, starting at the current time, and extending
# for len(x) number of hours.
times = np.arange(len(x)) * 3600000 + time.time()

source = ColumnDataSource(data=dict(x=x, y=y, times=times))

xdr = DataRange1d(sources=[source.columns("times")])
ydr = DataRange1d(sources=[source.columns("y")])

plot = Plot(x_range=xdr, y_range=ydr, min_border=80)

circle = Circle(x="times", y="y", fill_color="red", size=5, line_color="black")
plot.add_glyph(source, circle)

plot.add_layout(DatetimeAxis(), 'below')
plot.add_layout(DatetimeAxis(), 'left')

plot.add_tools(PanTool(), WheelZoomTool())

doc = Document()
doc.add(plot)

if __name__ == "__main__":
    filename = "dateaxis.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Date Axis Example"))
    print("Wrote %s" % filename)
    view(filename)
예제 #9
0
line2 = Line(x="dates", y="sunsets", line_color="red", line_width=2)
line2_glyph = Glyph(data_source=source,
                    xdata_range=xdr,
                    ydata_range=ydr,
                    glyph=line2)
plot.renderers.append(line2_glyph)

text = Text(x="dates", y="times", text="texts", angle=0, text_align="center")
text_glyph = Glyph(data_source=text_source,
                   xdata_range=xdr,
                   ydata_range=ydr,
                   glyph=text)
plot.renderers.append(text_glyph)

xaxis = DatetimeAxis(plot=plot, dimension=0)
yaxis = DatetimeAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)

legend = Legend(plot=plot,
                legends={
                    "sunrise": [line1_glyph],
                    "sunset": [line2_glyph]
                })
plot.renderers.append(legend)

session = HTMLFileSession("daylight.html")
session.add_plot(plot)

if __name__ == "__main__":