Пример #1
0
xdr = DataRange1d(sources=[source.columns("x")])
ydr = DataRange1d(sources=[source.columns("y")])

plot = Plot(title=None,
            x_range=xdr,
            y_range=ydr,
            plot_width=300,
            plot_height=300,
            h_symmetry=False,
            v_symmetry=False,
            min_border=0,
            toolbar_location=None)

glyph = Cross(x="x",
              y="y",
              size="sizes",
              line_color="#e6550d",
              fill_color=None,
              line_width=2)
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))

doc = Document()
doc.add(plot)
Пример #2
0
    def bokeh(self,
              glyphType="line",
              glyphSize=1,
              fillColor="red",
              lineColor="black",
              lineAlpha=1,
              fillAlpha=0.1,
              lineDash='solid'):

        #glyphs
        from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Marker, Asterisk, Circle,
                                          CircleCross, CircleX, Cross, Diamond,
                                          DiamondCross, InvertedTriangle,
                                          Square, SquareCross, SquareX,
                                          Triangle, X)

        #data
        from bokeh.models import ColumnDataSource

        from math import sqrt

        #Parameters of the histogram
        l = self.low
        h = self.high
        num = self.num
        bin_width = (h - l) / num
        x = list()
        y = list()
        center = l
        for v in self.values:
            if not math.isnan(v.mean):
                y.append(v.mean)
                x.append(center + bin_width / 2)
                center += bin_width

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

        glyph = None
        if glyphType == "square":
            glyph = Square(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(x='x',
                            y='y',
                            line_color=lineColor,
                            fill_color=fillColor,
                            line_alpha=lineAlpha,
                            size=glyphSize,
                            line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(x='x',
                          y='y',
                          line_color=lineColor,
                          fill_color=fillColor,
                          line_alpha=lineAlpha,
                          size=glyphSize,
                          line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(x='x',
                             y='y',
                             line_color=lineColor,
                             fill_color=fillColor,
                             line_alpha=lineAlpha,
                             size=glyphSize,
                             line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "errors":
            w = [bin_width for _ in x]
            h = [
                sqrt(v.variance / v.entries) if v.entries > 0 else 0.0
                for v in self.values
            ]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width='w',
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "histogram":
            w = [bin_width for _ in x]
            h = y
            y = [yy / 2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width='w',
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        else:
            glyph = Line(x='x',
                         y='y',
                         line_color=lineColor,
                         line_alpha=lineAlpha,
                         line_width=glyphSize,
                         line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Пример #3
0
    def bokeh(self,
              glyphType="line",
              glyphSize=1,
              fillColor="red",
              lineColor="black",
              lineAlpha=1,
              fillAlpha=0.1,
              lineDash='solid'):

        #glyphs
        from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Marker, Asterisk, Circle,
                                          CircleCross, CircleX, Cross, Diamond,
                                          DiamondCross, InvertedTriangle,
                                          Square, SquareCross, SquareX,
                                          Triangle, X)

        #data
        from bokeh.models import ColumnDataSource

        #Parameters of the histogram
        l = self.low
        h = self.high
        num = self.num
        bin_width = (h - l) / num
        x = list()
        center = l
        for _ in range(num):
            x.append(center + bin_width / 2)
            center += bin_width
        y = self.numericalValues
        ci = [2. * v for v in self.confidenceIntervalValues()]

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

        glyph = None
        if glyphType == "square":
            glyph = Square(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(x='x',
                            y='y',
                            line_color=lineColor,
                            fill_color=fillColor,
                            line_alpha=lineAlpha,
                            size=glyphSize,
                            line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(x='x',
                          y='y',
                          line_color=lineColor,
                          fill_color=fillColor,
                          line_alpha=lineAlpha,
                          size=glyphSize,
                          line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(x='x',
                             y='y',
                             line_color=lineColor,
                             fill_color=fillColor,
                             line_alpha=lineAlpha,
                             size=glyphSize,
                             line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "rect":
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height=0.1,
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "errors":
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height='ci',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "histogram":
            h = y
            y = [yy / 2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        else:
            glyph = Line(x='x',
                         y='y',
                         line_color=lineColor,
                         line_alpha=lineAlpha,
                         line_width=glyphSize,
                         line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Пример #4
0
    def plotbokeh(self, glyphType="line", glyphSize=1, fillColor="red",
                  lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'):

        # glyphs
        from bokeh.models.glyphs import Rect, Line
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Circle, Cross,
                                          Diamond, Square,
                                          Triangle)

        # data
        from bokeh.models import ColumnDataSource

        # Parameters of the histogram
        lo = self.low
        hi = self.high
        num = self.num
        bin_width = (hi-lo)/num
        x = list()
        y = list()
        center = lo
        for v in self.values:
            if not math.isnan(v.mean):
                y.append(v.mean)
                x.append(center+bin_width/2)
                center += bin_width

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

        glyph = None
        if glyphType == "square":
            glyph = Square(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "histogram":
            w = [bin_width for _ in x]
            h = y
            y = [yy/2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(
                x='x',
                y='y',
                width='w',
                height='h',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        else:
            glyph = Line(
                x='x',
                y='y',
                line_color=lineColor,
                line_alpha=lineAlpha,
                line_width=glyphSize,
                line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Пример #5
0
    def plotbokeh(self, glyphType="line", glyphSize=1, fillColor="red",
                  lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'):

        # glyphs
        from bokeh.models.glyphs import Rect, Line
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Circle, Cross,
                                          Diamond, Square,
                                          Triangle)

        # data
        from bokeh.models import ColumnDataSource

        # Parameters of the histogram
        lo = self.low
        hi = self.high
        num = self.numFilled
        bin_width = (hi-lo)/num
        x = list()
        center = lo
        for _ in range(num):
            x.append(center+bin_width/2)
            center += bin_width
        y = [v.entries for _, v in sorted(self.bins.items())]

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

        glyph = None
        if glyphType == "square":
            glyph = Square(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "rect":
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height=0.1,
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        elif glyphType == "errors":
            ci = [2.*v for v in self.confidenceIntervalValues()]
            source = ColumnDataSource(data=dict(x=x, y=y, ci=ci))
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height='ci',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        elif glyphType == "histogram":
            h = y
            y = [yy/2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, h=h))
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height='h',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        else:
            glyph = Line(
                x='x',
                y='y',
                line_color=lineColor,
                line_alpha=lineAlpha,
                line_width=glyphSize,
                line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Пример #6
0
    p = figure(plot_width=400, plot_height=400, title="title_title", toolbar_location=None)
    x = [1,2,3,4,5]
    sizes = [10]*len(x)
    circles = [1]*len(x)
    crosses = [2]*len(x)
    triangles = [3]*len(x)
    exes = [4]*len(x)
    asterisks = [5]*len(x)
    diamonds = [6]*len(x)
    squares = [7]*len(x)

    scatter_data = ColumnDataSource(dict(x=x, circles=circles, crosses=crosses, triangles=triangles, exes=exes, asterisks=asterisks, diamonds=diamonds, squares=squares, sizes=sizes))

    glyphs = []
    glyphs.append(Circle(x="x", y="circles", size="sizes", fill_color="red", name="the_circles"))
    glyphs.append(Cross(x="x", y="crosses", size="sizes", fill_color="blue", name="the_crosses"))
    glyphs.append(Triangle(x="x", y="triangles", size="sizes", fill_color="green", name="the_triangles"))
    glyphs.append(X(x="x", y="exes", size="sizes", fill_color="purple", name="the_xs"))
    glyphs.append(Asterisk(x="x", y="asterisks", size="sizes", fill_color="orange", name="the_asterisks"))
    glyphs.append(Diamond(x="x", y="diamonds", size="sizes", fill_color="yellow", name="the_diamonds"))
    glyphs.append(Square(x="x", y="squares", size="sizes", fill_color="gray", name="the_squares"))

    legend_items = []
    for glyph in glyphs:
        renderer = p.add_glyph(scatter_data, glyph)
        renderer.name = glyph.name
        legend_items.append((renderer.name, [renderer]))
    
    legend = Legend(
        items=legend_items,
        name="the_legend",