Exemple #1
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)
Exemple #2
0
N = 9
x = np.linspace(-2, 2, N)
y = x**2
sizes = np.linspace(10, 20, N)

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

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 = Square(x="x", y="y", size="sizes", fill_color="#74add1")
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)

show(plot)
Exemple #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)
    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)
    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)
Exemple #6
0
    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",
        label_text_font_size='5pt',
        glyph_width=20,
        glyph_height=10,
        location="center_right",
        padding=5,
Exemple #7
0
               size=4,
               color="black",
               alpha=0.4)
glMohrFigure2_angle_label = LatexLabel(text="",
                                       x=20,
                                       y=330,
                                       render_mode='css',
                                       text_color='firebrick',
                                       x_units='screen',
                                       y_units='screen')
figure2.add_layout(glMohrFigure2_angle_label)

### Figure 3: Define Geometry
Rotating_Plane_glyph = Square(x='x',
                              y='y',
                              angle='angle',
                              size='size',
                              fill_color=c_green,
                              fill_alpha=0.5)
Rotating_Plane_red_glyph = Square(x='x',
                                  y='y',
                                  angle='angle',
                                  size='size',
                                  fill_color='firebrick',
                                  fill_alpha=0.5)

Rotating_Axis_X_glyph = Arrow(end=NormalHead(fill_color=c_green, size=15),
                              x_start='xS',
                              y_start='yS',
                              x_end='xE',
                              y_end='yE',
                              source=f3.Rotating_Axis_X_source)