コード例 #1
0
ファイル: bokeh_backend.py プロジェクト: codeaudit/artemis
def _plot(model = None, **kwargs):
    session = _get_or_make_session()
    # Build Gridplot:
    num = _SUBPLOT_DICT["num"]
    rows = _SUBPLOT_DICT["rows"]
    cols = _SUBPLOT_DICT["cols"]
    global _GRIDPLOT
    if num == 1:
        children = [[None for _ in xrange(_SUBPLOT_DICT["cols"])] for _ in xrange(_SUBPLOT_DICT["rows"])]
    else:
        children = _GRIDPLOT.children
    newplot = model(**kwargs)
    global _CURRENT_PLOT
    _CURRENT_PLOT = newplot
    global _ALL_PLOTS
    _ALL_PLOTS[newplot._id] = newplot
    row_coordinate = int(np.ceil(float(num) / cols) - 1)
    col_coordinate = num % cols -1 if num % cols != 0 else cols -1
    children[row_coordinate][col_coordinate] = newplot
    _GRIDPLOT = GridPlot()
    _GRIDPLOT.children = children
    _CURRENT_SESSION.document.clear()
    _GRIDPLOT._detach_document()
    print _GRIDPLOT
    _CURRENT_SESSION.document.add_root(_GRIDPLOT)
    # global _CURRENT_PLOT
    # _CURRENT_PLOT = newplot
    return newplot
コード例 #2
0
    def make_2d_facet_plot(self, facet=None):
        # print ("make_2d_facet_plot")
        """Creates the grid of plots when there are both x and y facets.

        Returns:
          GridPlot: grid of x and y facet combinations

        """
        # ToDo: gracefully handle large combinations of facets
        all_facets_x = self.make_facets('x')
        all_facets_y = self.make_facets('y')

        grid_plots = []

        # y faceting down column
        for facets_y in all_facets_y:

            # x faceting across row
            row = []
            for facets_x in all_facets_x:

                # build the facets and title
                facets = facets_x + facets_y
                title = self.facet_title(facets)

                # must filter by any extra facets provided for facet tab
                if facet:
                    filter_facets = facets + facet
                else:
                    filter_facets = facets

                # if len(self.filter_widgets) == 0:
                #     filtered_df = self.query('/bench/col/dict/bare')
                # else:
                filtered_df = self.df

                df = self.facet_data(filter_facets, filtered_df)
                plot = self.make_single_plot(df=df,
                                             title=title,
                                             plot_height=200,
                                             plot_width=200,
                                             tools="pan,wheel_zoom,reset",
                                             facet=facets)
                row.append(plot)

            # append the row to the list of rows
            grid_plots.append(row)

            self.hide_internal_axes(grid_plots)

        # return the grid of plots as the plot
        return GridPlot(children=grid_plots,
                        plot_width=200 * len(all_facets_x))
コード例 #3
0
    def make_1d_facet_plot(self, facet=None):
        # print ("make_1d_facet_plot")
        """Creates the faceted plots when a facet is added to the x axis.

        Returns:
          GridPlot: a grid of plots, where each plot has subset of data

        """
        if self.facet_x:
            all_facets = self.make_facets('x')
        else:
            all_facets = self.make_facets('y')

        plots = []

        # loop over facets and create single plots for data subset
        for facets in all_facets:
            title = self.facet_title(facets)

            if facet:
                facets += facet

            # if len(self.filter_widgets) == 0:
            #     filtered_df = self.query('/bench/col/dict/bare')
            # else:
            filtered_df = self.df

            df = self.facet_data(facets, filtered_df)
            plot = self.make_single_plot(df=df,
                                         title=title,
                                         plot_height=200,
                                         plot_width=200,
                                         tools="pan,wheel_zoom,reset",
                                         facet=facets)

            # append single plot to list of plots
            plots.append(plot)

        # create squarish grid based on number of plots
        chunk_size = int(np.ceil(np.sqrt(len(plots))))

        # create list of lists of plots, where each list of plots is a row
        grid_plots = []
        for i in range(0, len(plots), chunk_size):
            chunk = plots[i:i + chunk_size]
            grid_plots.append(chunk)

        self.hide_internal_axes(grid_plots)

        # return the grid as the plot
        return GridPlot(children=grid_plots, plot_width=200 * chunk_size)
コード例 #4
0
p2.line(x='time', y='macd9', color='blue', source=source)
p2.segment(x0='time',
           y0=0,
           x1='time',
           y1='macdh',
           line_width=6,
           color='black',
           alpha=0.5,
           source=source)

mean = Slider(title="mean", value=0, start=-0.01, end=0.01, step=0.001)
stddev = Slider(title="stddev", value=0.04, start=0.01, end=0.1, step=0.01)
mavg = Select(value=MA12, options=[MA12, MA26, EMA12, EMA26])

curdoc().add_root(
    VBox(HBox(mean, stddev, mavg), GridPlot(children=[[p], [p2]])))


def _create_prices(t):
    last_average = 100 if t == 0 else source.data['average'][-1]
    returns = asarray(lognormal(mean.value, stddev.value, 1))
    average = last_average * cumprod(returns)
    high = average * exp(abs(gamma(1, 0.03, size=1)))
    low = average / exp(abs(gamma(1, 0.03, size=1)))
    delta = high - low
    open = low + delta * uniform(0.05, 0.95, size=1)
    close = low + delta * uniform(0.05, 0.95, size=1)
    return open[0], high[0], low[0], close[0], average[0]


def _moving_avg(prices, days=10):
コード例 #5
0
ファイル: calendars.py プロジェクト: xuexianwu/bokeh
    rect = Rect(x="holidays_days", y="holidays_weeks", width=0.9, height=0.9, fill_color="pink", line_color="indianred")
    rect_renderer = plot.add_glyph(holidays_source, rect)

    text = Text(x="days", y="weeks", text="month_days", angle=0, text_align="center", text_baseline="middle")
    plot.add_glyph(source, text)

    xaxis = CategoricalAxis()
    xaxis.major_label_text_font_size = "8pt"
    xaxis.major_label_standoff = 0
    xaxis.major_tick_line_color = None
    xaxis.axis_line_color = None
    plot.add_layout(xaxis, 'above')

    hover_tool = HoverTool(plot=plot, renderers=[rect_renderer], tooltips=[("Holiday", "@month_holidays")])
    plot.tools.append(hover_tool)

    return plot

months = [ [ make_calendar(2014, 3*i + j + 1) for j in range(3) ] for i in range(4) ]
grid = GridPlot(title="Calendar 2014", toolbar_location=None, children=months)

doc = Document()
doc.add(grid)

if __name__ == "__main__":
    filename = "calendars.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Calendar 2014"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #6
0
    plot.add_glyph(source, text)

    xaxis = CategoricalAxis()
    xaxis.major_label_text_font_size = "8pt"
    xaxis.major_label_standoff = 0
    xaxis.major_tick_line_color = None
    xaxis.axis_line_color = None
    plot.add_layout(xaxis, 'above')

    hover_tool = HoverTool(plot=plot,
                           renderers=[rect_renderer],
                           tooltips=[("Holiday", "@month_holidays")])
    plot.tools.append(hover_tool)

    return plot


months = [[make_calendar(2014, 3 * i + j + 1) for j in range(3)]
          for i in range(4)]
grid = GridPlot(toolbar_location=None, children=months)

doc = Document()
doc.add_root(grid)

if __name__ == "__main__":
    filename = "calendars.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Calendar 2014"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #7
0
p2.line(x='time', y='macd9', color='blue', source=source)
p2.segment(x0='time',
           y0=0,
           x1='time',
           y1='macdh',
           line_width=6,
           color='black',
           alpha=0.5,
           source=source)

mean = Slider(title="mean", value=0, start=-0.01, end=0.01, step=0.001)
stddev = Slider(title="stddev", value=0.04, start=0.01, end=0.1, step=0.01)
mavg = Select(value=MA12, options=[MA12, MA26, EMA12, EMA26])

curdoc().add_root(
    VBox(HBox(mean, stddev, mavg, width=800), GridPlot(children=[[p], [p2]])))


def _create_prices(t):
    last_average = 100 if t == 0 else source.data['average'][-1]
    returns = asarray(lognormal(mean.value, stddev.value, 1))
    average = last_average * cumprod(returns)
    high = average * exp(abs(gamma(1, 0.03, size=1)))
    low = average / exp(abs(gamma(1, 0.03, size=1)))
    delta = high - low
    open = low + delta * uniform(0.05, 0.95, size=1)
    close = low + delta * uniform(0.05, 0.95, size=1)
    return open[0], high[0], low[0], close[0], average[0]


def _moving_avg(prices, days=10):
コード例 #8
0
    'Boston': {
        'airport': 'BOS',
        'title': 'Boston, MA',
    },
    'Seattle': {
        'airport': 'SEA',
        'title': 'Seattle, WA',
    }
}

city_select = Select(value=city, title='City', options=sorted(cities.keys()))
distribution_select = Select(value=distribution,
                             title='Distribution',
                             options=['Discrete', 'Smooth'])

df = pd.read_csv(join(dirname(__file__), 'data/2015_weather.csv'))
source = get_dataset(df, cities[city]['airport'], distribution)
tplot = make_temperature_plot(source, cities[city]['title'])
pplot = make_precipitation_plot(source)

city_select.on_change('value', update_plot)
distribution_select.on_change('value', update_plot)

controls = VBox(city_select, distribution_select)

# add to document
curdoc().add_root(
    HBox(controls,
         GridPlot(children=[[tplot], [pplot]], toolbar_location=None),
         width=1200))
コード例 #9
0
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

    line = Line(x='x', y='y', line_color="#666699", line_width=2)
    plot.add_glyph(lines_source, line)

    circle = Circle(
        x=xname, y=yname, size=12,
        fill_color="#cc6633", line_color="#cc6633", fill_alpha=0.5
    )
    plot.add_glyph(circles_source, circle)

    return plot

#where will this comment show up
I   = make_plot('I',   'xi',   'yi')
II  = make_plot('II',  'xii',  'yii')
III = make_plot('III', 'xiii', 'yiii')
IV  = make_plot('IV',  'xiv',  'yiv')

grid = GridPlot(children=[[I, II], [III, IV]])

doc = Document()
doc.add(grid)

if __name__ == "__main__":
    filename = "anscombe.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Anscombe's Quartet"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #10
0
ファイル: iris_splom.py プロジェクト: zlxs23/bokeh
    plot.add_tools(PanTool(), WheelZoomTool())

    return plot


xattrs = ["petal_length", "petal_width", "sepal_width", "sepal_length"]
yattrs = list(reversed(xattrs))
plots = []

for y in yattrs:
    row = []
    for x in xattrs:
        xax = (y == yattrs[-1])
        yax = (x == xattrs[0])
        plot = make_plot(x, y, xax, yax)
        row.append(plot)
    plots.append(row)

grid = GridPlot(children=plots)

doc = Document()
doc.add_root(grid)

if __name__ == "__main__":
    filename = "iris_splom.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Iris Data SPLOM"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #11
0
ファイル: grid.py プロジェクト: ViennaChen/bokeh
    if ydr is None: ydr = DataRange1d()

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

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

    plot.add_glyph(source, Line(x=xname, y=yname, line_color=line_color))

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

    return plot


plot1 = make_plot(source, "x", "y1", "blue")
plot2 = make_plot(source, "x", "y2", "red", xdr=plot1.x_range)
plot3 = make_plot(source, "x", "y3", "green")
plot4 = make_plot(source, "x", "y4", "black")

grid = GridPlot(children=[[plot1, plot2], [plot3, plot4]])

doc = Document()
doc.add_root(grid)

if __name__ == "__main__":
    filename = "grid.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Grid Plot Example"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #12
0
def test_grid_plot_responsive_property_is_fixed_by_default():
    gp = GridPlot()
    assert gp.responsive is 'fixed'
コード例 #13
0
# Categorical plot
source = ColumnDataSource(dict(
    names  = list(css3_colors.Name),
    groups = list(css3_colors.Group),
    colors = list(css3_colors.Color),
))
xdr = FactorRange(factors=list(css3_colors.Group.unique()))
ydr = FactorRange(factors=list(reversed(css3_colors.Name)))
#cat_plot = Plot(title="CSS3 Color Names", x_range=xdr, y_range=ydr, min_border=1, responsive='box')
#rect = Rect(x="groups", y="names", width=1, height=1, fill_color="colors", line_color=None)
#cat_plot.add_glyph(source, rect)
#xaxis = CategoricalAxis(major_label_orientation=pi/4)
#cat_plot.add_layout(xaxis, 'below')
#cat_plot.add_layout(CategoricalAxis(), 'left')

#row1 = Row(children=[plot1, plot2])
#row2col1 = Column(children=[plot3, plot4])
#row2 = Row(children=[row2col1, cat_plot])
#row3 = Row(children=[plot3, plot4])

doc = Document()
#doc.add_root(Column(children=[row1, row2]))
doc.add_root(GridPlot([[plot1, plot2], [plot3, plot4]], toolbar_location='above', responsive='fixed'))

if __name__ == "__main__":
    filename = "grid_layout.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Grid Layout"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #14
0
ファイル: plotting_old.py プロジェクト: ltcguthrie/cameo
 def _plot_bokeh_grid(self):
     if len(self.plots) > 0:
         grid = GridPlot(children=partition(self.plots, self.nrows), title=self.title)
         plotting.show(grid)
コード例 #15
0
        )
        plot.add_glyph(text_source, text)

    return plot

xattrs = ["petal_length", "petal_width", "sepal_width", "sepal_length"]
yattrs = list(reversed(xattrs))
plots = []

for y in yattrs:
    row = []
    for x in xattrs:
        xax = (y == yattrs[-1])
        yax = (x == xattrs[0])
        text = x if (x==y) else None
        plot = make_plot(x, y, xax, yax, text)
        row.append(plot)
    plots.append(row)

grid = GridPlot(children=plots, title="iris_splom")

doc = Document()
doc.add(grid)

if __name__ == "__main__":
    filename = "iris_splom.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Iris Data SPLOM"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #16
0
def test_grid_plot_sizing_mode_property_is_fixed_by_default():
    gp = GridPlot()
    assert gp.sizing_mode is 'fixed'
コード例 #17
0
    p.title = 'Color Scatter 1'
    p.title_location = 'right'

    p.scatter(x,
              y,
              radius=radii,
              fill_color=colors,
              fill_alpha=0.6,
              line_color=None)
    return p


layout = GridPlot(children=[
    [p(), p(), p(), p()],
    [p(), p(), p(), p()],
    [p(), p(), p(), p()],
    [p(), p(), p(), p()],
],
                  toolbar_location=None,
                  sizing_mode='stretch_both')

toolbar_locations = [None, 'above', 'right', 'below', 'left']
tb = 1

#layout = GridPlot(
#    children=[
#        [p(), p()],
#    ],
#    toolbar_location=toolbar_locations[tb],
#    responsive='fixed'
#)
show(layout)
コード例 #18
0
    plot.add_glyph(lines_source, line)

    circle = Circle(x=xname,
                    y=yname,
                    size=12,
                    fill_color="#cc6633",
                    line_color="#cc6633",
                    fill_alpha=0.5)
    plot.add_glyph(circles_source, circle)

    return plot


#where will this comment show up
I = make_plot('I', 'xi', 'yi')
II = make_plot('II', 'xii', 'yii')
III = make_plot('III', 'xiii', 'yiii')
IV = make_plot('IV', 'xiv', 'yiv')

grid = GridPlot(children=[[I, II], [III, IV]], plot_width=800)

doc = Document()
doc.add(grid)

if __name__ == "__main__":
    filename = "anscombe.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Anscombe's Quartet"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #19
0
ファイル: main.py プロジェクト: yihongfa/bokeh
    corr.title = '%s returns vs. %s returns' % (t1, t2)
    ts1.title, ts2.title = t1, t2

def update_stats(data, t1, t2):
    stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe())

ticker1.on_change('value', ticker1_change)
ticker2.on_change('value', ticker2_change)

def selection_change(attrname, old, new):
    t1, t2 = ticker1.value, ticker2.value
    data = get_data(t1, t2)
    selected = source.selected['1d']['indices']
    if selected:
        data = data.iloc[selected, :]
    update_stats(data, t1, t2)

source.on_change('selected', selection_change)

# set up layout
stats_box = VBox(stats)
input_box = VBox(ticker1, ticker2)
main_row = HBox(input_box, corr, stats_box)
layout = VBox(main_row, GridPlot(children=[[ts1], [ts2]]))

# initialize
update()

curdoc().add_root(layout)
コード例 #20
0
p.line(x='time', y='average', alpha=0.2, line_width=3, color='navy', source=source)
p.line(x='time', y='ma', alpha=0.8, line_width=2, color='orange', source=source)
p.segment(x0='time', y0='low', x1='time', y1='high', line_width=2, color='black', source=source)
p.segment(x0='time', y0='open', x1='time', y1='close', line_width=8, color='color', source=source)

p2 = Figure(plot_height=250, x_range=p.x_range, tools="xpan,xwheel_zoom,xbox_zoom,reset")
p2.line(x='time', y='macd', color='red', source=source)
p2.line(x='time', y='macd9', color='blue', source=source)
p2.segment(x0='time', y0=0, x1='time', y1='macdh', line_width=6, color='black', alpha=0.5, source=source)

mean = Slider(title="mean", value=0, start=-0.01, end=0.01, step=0.001)
stddev = Slider(title="stddev", value=0.04, start=0.01, end=0.1, step=0.01)
mavg = Select(value=MA12, options=[MA12, MA26, EMA12, EMA26])

curdoc().add_root(VBox(HBox(mean, stddev, mavg, width=800), GridPlot(children=[[p], [p2]])))


def create_random_corr_matrix(n):
    m = 2 * np.random.random_sample((n, n)) - 5
    return np.tril(m) + np.tril(m, -1).T


def create_random_corr_dataframe(n):
    m = create_random_corr_matrix(n)

    def convert_to_title(num):
        title = ''
        alist = string.uppercase
        while num:
            mod = (num - 1) % 26
コード例 #21
0
ファイル: with_bokeh.py プロジェクト: ehukim/cameo
 def _make_grid(grid):
     return GridPlot(children=partition(grid.plots, grid.n_rows),
                     name=grid.title)