コード例 #1
0
ファイル: gears.py プロジェクト: tarzzz/bokeh
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,
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=800,
                height=800)
    plot.tools.extend(
        [PanTool(plot=plot),
         WheelZoomTool(plot=plot),
         ResetTool(plot=plot)])

    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)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    glyph = Gear(x=0,
                 y=0,
                 module=module,
                 teeth=sun_teeth,
                 angle=0,
                 fill_color=fill_color[2],
                 line_color=line_color)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    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)
        renderer = Glyph(data_source=source,
                         xdata_range=xdr,
                         ydata_range=ydr,
                         glyph=glyph)
        plot.renderers.append(renderer)

    return plot
コード例 #2
0
    # default in FillProps, which is "gray".
    fill_color="color",

    # An alternative form that explicitly sets a default value:
    #fill_color={"default": "red", "field": "color"},

    # Note that line_color is set to a fixed value. This can be any of
    # the SVG named 147 colors, or a hex color string starting with "#",
    # or a string "rgb(r,g,b)" or "rgba(r,g,b,a)".
    # Any other string will be interpreted as a field name to look up
    # on the datasource.
    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 = LinearAxis(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("colorspec.html")
コード例 #3
0
x = np.linspace(-2 * pi, 2 * pi, 1000)
y = sin(x)
z = cos(x)

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

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

line_glyph = Line(x="x", y="y", line_color="blue")

renderer = Glyph(data_source=source,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=line_glyph)

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=50)
xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
yaxis = LinearAxis(plot=plot, dimension=1, location="left")

pantool = PanTool(dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dimensions=["width", "height"])
previewsave = PreviewSaveTool(plot=plot)
objectexplorer = ObjectExplorerTool()

plot.renderers.append(renderer)
plot.tools = [pantool, wheelzoomtool, previewsave, objectexplorer]

sess = session.HTMLFileSession("line.html")
コード例 #4
0
        start=start_angles,
        end=end_angles,
        colors=[colors[browser] for browser in browsers],
    ))
plot.data_sources.append(browsers_source)

glyph = Wedge(x=0,
              y=0,
              radius=1,
              line_color="white",
              line_width=2,
              start_angle="start",
              end_angle="end",
              fill_color="colors")
renderer = Glyph(data_source=browsers_source,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=glyph)
plot.renderers.append(renderer)


def polar_to_cartesian(r, start_angles, end_angles):
    cartesian = lambda r, alpha: (r * cos(alpha), r * sin(alpha))
    points = []

    for start, end in zip(start_angles, end_angles):
        points.append(cartesian(r, (end + start) / 2))

    return zip(*points)


first = True
コード例 #5
0
    fy=[],
    ty=[],
))

xdr = DataRange1d(sources=[source.columns("x")])
ydr = DataRange1d(sources=[source.columns("fy")])

plot = Plot(data_sources=[source],
            x_range=xdr,
            y_range=ydr,
            plot_width=800,
            plot_height=400)

line_f = Line(x="x", y="fy", line_color="blue", line_width=2)
line_f_glyph = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=line_f)
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)
コード例 #6
0
    ))

xdr = DataRange1d(sources=[source.columns("dates")])
ydr = DataRange1d(sources=[source.columns("sunrises", "sunsets")])

title = "Daylight Hours - Warsaw, Poland"
plot = Plot(title=title,
            data_sources=[source, patch1_source, patch2_source, text_source],
            x_range=xdr,
            y_range=ydr,
            width=800,
            height=400)

patch1 = Patch(x="dates", y="times", fill_color="skyblue", fill_alpha=0.8)
patch1_glyph = Glyph(data_source=patch1_source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=patch1)
plot.renderers.append(patch1_glyph)

patch2 = Patch(x="dates", y="times", fill_color="orange", fill_alpha=0.8)
patch2_glyph = Glyph(data_source=patch2_source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=patch2)
plot.renderers.append(patch2_glyph)

line1 = Line(x="dates", y="sunrises", line_color="yellow", line_width=2)
line1_glyph = Glyph(data_source=source,
                    xdata_range=xdr,
                    ydata_range=ydr,
                    glyph=line1)
コード例 #7
0
    def create(self):
        manufacturers = sorted(mpg["manufacturer"].unique())
        models = sorted(mpg["model"].unique())
        transmissions = sorted(mpg["trans"].unique())
        drives = sorted(mpg["drv"].unique())
        classes = sorted(mpg["class"].unique())

        manufacturer_select = Select(title="Manufacturer:",
                                     value="All",
                                     options=["All"] + manufacturers)
        manufacturer_select.on_change('value', self.on_manufacturer_change)
        model_select = Select(title="Model:",
                              value="All",
                              options=["All"] + models)
        model_select.on_change('value', self.on_model_change)
        transmission_select = Select(title="Transmission:",
                                     value="All",
                                     options=["All"] + transmissions)
        transmission_select.on_change('value', self.on_transmission_change)
        drive_select = Select(title="Drive:",
                              value="All",
                              options=["All"] + drives)
        drive_select.on_change('value', self.on_drive_change)
        class_select = Select(title="Class:",
                              value="All",
                              options=["All"] + classes)
        class_select.on_change('value', self.on_class_change)

        columns = [
            TableColumn(field="manufacturer",
                        header="Manufacturer",
                        type="autocomplete",
                        source=manufacturers),
            TableColumn(field="model",
                        header="Model",
                        type="autocomplete",
                        source=models),
            TableColumn(field="displ",
                        header="Displacement",
                        type="numeric",
                        format="0.00"),
            TableColumn(field="year", header="Year", type="numeric"),
            TableColumn(field="cyl", header="Cylinders", type="numeric"),
            TableColumn(field="trans",
                        header="Transmission",
                        type="dropdown",
                        strict=True,
                        source=transmissions),
            TableColumn(field="drv",
                        header="Drive",
                        type="autocomplete",
                        strict=True,
                        source=drives),
            TableColumn(field="class",
                        header="Class",
                        type="autocomplete",
                        strict=True,
                        source=classes),
            TableColumn(field="cty", header="City MPG", type="numeric"),
            TableColumn(field="hwy", header="Highway MPG", type="numeric"),
        ]
        handson_table = HandsonTable(source=self.source,
                                     columns=columns,
                                     sorting=True)

        xdr = DataRange1d(sources=[self.source.columns("index")])
        #xdr = FactorRange(factors=manufacturers)
        ydr = DataRange1d(
            sources=[self.source.columns("cty"),
                     self.source.columns("hwy")])
        plot = Plot(title=None,
                    data_sources=[self.source],
                    x_range=xdr,
                    y_range=ydr,
                    plot_width=800,
                    plot_height=300)
        xaxis = LinearAxis(plot=plot)
        plot.below.append(xaxis)
        yaxis = LinearAxis(plot=plot)
        ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
        plot.left.append(yaxis)
        cty = Glyph(data_source=self.source,
                    glyph=Circle(x="index", y="cty", fill_color="green"))
        hwy = Glyph(data_source=self.source,
                    glyph=Circle(x="index", y="hwy", fill_color="red"))
        select_tool = BoxSelectTool(renderers=[cty, hwy], select_y=False)
        plot.tools.append(select_tool)
        overlay = BoxSelectionOverlay(tool=select_tool)
        plot.renderers.extend([cty, hwy, ygrid, overlay])

        controls = VBox(children=[
            manufacturer_select, model_select, transmission_select,
            drive_select, class_select
        ],
                        width=200)
        top_panel = HBox(children=[controls, plot])
        layout = VBox(children=[top_panel, handson_table])

        return layout
コード例 #8
0
                            major_label_orientation=pi / 4,
                            location="top")
xaxis_bottom = CategoricalAxis(plot=plot,
                               dimension=0,
                               major_label_orientation=pi / 4,
                               location="bottom")
yaxis = CategoricalAxis(plot=plot, dimension=1)

# XXX: Wrong radius. Doesn't respect 'radius'. 'line_color' on 'rect' affects 'circle'.
# circle = Circle(x="groups", y="names", radius=1, fill_color="colors")
# plot.renderers.append(Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=circle))

rect = Rect(x="groups",
            y="names",
            width=1,
            height=1,
            fill_color="colors",
            line_color=None)
plot.renderers.append(
    Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=rect))

doc = Document()
doc.add(plot)

if __name__ == "__main__":
    filename = "colors.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "CSS3 Color Names"))
    print("Wrote %s" % filename)
    view(filename)
コード例 #9
0
ファイル: boxviolin.py プロジェクト: vishalbelsare/xlang
def make_box_violin_plot(data, num_bins, maxwidth=0.9):
    """ 
    data: dict[Str -> List[Number]]
    maxwidth: float
        Maximum width of tornado plot within each factor/facet

    Returns the plot object 
    """

    df = pd.DataFrame(columns=["group", "centers", "width", "height", "texts"])
    bar_height = 50
    bins = [0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6]
    # Compute histograms, while keeping track of max Y values and max counts
    for i, (group, vals) in enumerate(data.iteritems()):
        hist, edges = np.histogram(vals, bins)
        df = df.append(
            pd.DataFrame(
                dict(
                    group=group,
                    centers=np.arange(len(hist)) * bar_height,
                    width=np.log10(hist),
                    height=np.ones(hist.shape) * bar_height,
                    texts=map(str, hist),
                )))

    df.replace(-np.inf, 0)

    # Normalize the widths
    df["width"] *= (maxwidth / df["width"].max())

    ds = ColumnDataSource(df)

    xdr = FactorRange(factors=sorted(df["group"].unique()))
    ydr = DataRange1d(sources=[ds.columns("centers")])

    plot = Plot(data_sources=[ds],
                x_range=xdr,
                y_range=ydr,
                title="Degree Distribution",
                plot_width=750,
                plot_height=600,
                tools=[])
    xaxis = CategoricalAxis(plot=plot,
                            location="bottom",
                            axis_label="number of nodes")
    #yaxis = LogAxis(plot=plot, location="left", axis_label="degree")
    plot.below.append(xaxis)
    #plot.above.append(yaxis)

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

    glyph = Rect(x="group", y="centers", width="width", height="height")
    text_glyph = Text(x="group",
                      y="centers",
                      text="texts",
                      text_baseline="middle",
                      text_align="center")
    plot.renderers.append(
        Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=glyph))
    plot.renderers.append(
        Glyph(data_source=ds,
              xdata_range=xdr,
              ydata_range=ydr,
              glyph=text_glyph))

    return plot