コード例 #1
0
def population():
    xdr = FactorRange(factors=years)
    ydr = DataRange1d(
        sources=[source_known.columns("y"),
                 source_predicted.columns("y")])

    plot = Plot(title=None,
                x_range=xdr,
                y_range=ydr,
                plot_width=800,
                plot_height=200)

    plot.add_layout(CategoricalAxis(major_label_orientation=pi / 4), 'below')

    line_known = Line(x="x", y="y", line_color="violet", line_width=2)
    line_known_glyph = plot.add_glyph(source_known, line_known)

    line_predicted = Line(x="x",
                          y="y",
                          line_color="violet",
                          line_width=2,
                          line_dash="dashed")
    line_predicted_glyph = plot.add_glyph(source_predicted, line_predicted)

    plot.add_layout(
        Legend(orientation="bottom_right",
               legends=dict(known=[line_known_glyph],
                            predicted=[line_predicted_glyph])))

    return plot
コード例 #2
0
    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=None,
                         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])))
コード例 #3
0
def population():
    xdr = FactorRange(factors=years)
    ydr = DataRange1d(sources=[source_known.columns("y"), source_predicted.columns("y")])

    plot = Plot(title=None, data_sources=[source_known, source_predicted], x_range=xdr, y_range=ydr, plot_width=800, plot_height=200)

    xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4)
    # yaxis = LinearAxis(plot=plot, dimension=1, ...)

    line_known = Line(x="x", y="y", line_color="violet", line_width=2)
    line_known_glyph = Glyph(data_source=source_known, xdata_range=xdr, ydata_range=ydr, glyph=line_known)
    plot.renderers.append(line_known_glyph)

    line_predicted = Line(x="x", y="y", line_color="violet", line_width=2, line_dash="dashed")
    line_predicted_glyph = Glyph(data_source=source_predicted, xdata_range=xdr, ydata_range=ydr, glyph=line_predicted)
    plot.renderers.append(line_predicted_glyph)

    legend = Legend(plot=plot, orientation="bottom_right", legends=dict(known=[line_known_glyph], predicted=[line_predicted_glyph]))
    plot.renderers.append(legend)

    return plot
コード例 #4
0
def pyramid():
    xdr = DataRange1d(sources=[
        source_pyramid.columns("male"),
        source_pyramid.columns("female")
    ])
    ydr = DataRange1d(sources=[source_pyramid.columns("groups")])

    plot = Plot(title=None,
                x_range=xdr,
                y_range=ydr,
                plot_width=600,
                plot_height=600)

    xaxis = LinearAxis()
    plot.add_layout(xaxis, 'below')
    yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=5))
    plot.add_layout(yaxis, 'left')

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    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 = plot.add_glyph(source_pyramid, male_quad)

    female_quad = Quad(left=0,
                       right="female",
                       bottom="groups",
                       top="shifted",
                       fill_color="#CFF09E")
    female_quad_glyph = plot.add_glyph(source_pyramid, female_quad)

    plot.add_layout(
        Legend(
            legends=dict(Male=[male_quad_glyph], Female=[female_quad_glyph])))

    return plot
コード例 #5
0
def pyramid():
    xdr = DataRange1d(sources=[source_pyramid.columns("male"), source_pyramid.columns("female")])
    ydr = DataRange1d(sources=[source_pyramid.columns("groups")])

    plot = Plot(title=None, data_sources=[source_pyramid], x_range=xdr, y_range=ydr, plot_width=600, plot_height=600)

    xaxis = LinearAxis(plot=plot, dimension=0)
    yaxis = LinearAxis(plot=plot, dimension=1, ticker=SingleIntervalTicker(interval=5))

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

    male_quad = Quad(left="male", right=0, bottom="groups", top="shifted", fill_color="blue")
    male_quad_glyph = Glyph(data_source=source_pyramid, xdata_range=xdr, ydata_range=ydr, glyph=male_quad)
    plot.renderers.append(male_quad_glyph)

    female_quad = Quad(left=0, right="female", bottom="groups", top="shifted", fill_color="violet")
    female_quad_glyph = Glyph(data_source=source_pyramid, xdata_range=xdr, ydata_range=ydr, glyph=female_quad)
    plot.renderers.append(female_quad_glyph)

    legend = Legend(plot=plot, legends=dict(Male=[male_quad_glyph], Female=[female_quad_glyph]))
    plot.renderers.append(legend)

    return plot
コード例 #6
0
ファイル: daylight.py プロジェクト: tarzzz/bokeh
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__":
    filename = "daylight.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Daylight Plot"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #7
0
ファイル: daylight.py プロジェクト: weikang9009/bokeh
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__":
    filename = "daylight.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Daylight Plot"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #8
0
plot.add_layout(line_f_glyph)

line_t = Line(x="x", y="ty", line_color="red", line_width=2)
line_t_glyph = plot.add_glyph(source, line_t)
plot.add_layout(line_t_glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

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

xgrid = Grid(dimension=0, ticker=xaxis.ticker)
ygrid = Grid(dimension=1, ticker=yaxis.ticker)

legend = Legend(orientation="bottom_left")
plot.add_layout(legend)


def on_slider_value_change(obj, attr, old, new):
    global order
    order = int(new)
    update_data()


def on_text_value_change(obj, attr, old, new):
    try:
        global expr
        expr = sy.sympify(new, dict(x=xs))
    except (sy.SympifyError, TypeError, ValueError) as exception:
        dialog.content = str(exception)
コード例 #9
0
plot.renderers.append(line_f_glyph)

line_t = Line(x="x", y="ty", line_color="red", line_width=2)
line_t_glyph = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=line_t)
plot.renderers.append(line_t_glyph)

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)

legend = Legend(plot=plot, orientation="bottom_left")
plot.renderers.append(legend)


def on_slider_value_change(obj, attr, old, new):
    global order
    order = int(new)
    update_data()


def on_text_value_change(obj, attr, old, new):
    try:
        global expr
        expr = sy.sympify(new, dict(x=xs))
    except (sy.SympifyError, TypeError, ValueError) as exception:
        dialog.content = str(exception)