Example #1
0
class TestRect(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Rect
        self.test_rect = Rect()

    def test_expected_properties(self):
        expected_properties = set(['x','y','width','height','angle'])
        actual_properties = get_prop_set(type(self.test_rect))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_rect.x,'x')
        self.assertEqual(self.test_rect.y,'y')
        self.assertEqual(self.test_rect.width,'width')
        self.assertEqual(self.test_rect.height,'height')   
        self.assertEqual(self.test_rect.angle,'angle')
        self.assertEqual(self.test_rect.__view_model__,'rect')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_rect.to_glyphspec(), {'line_color': {'value': 'black'}, 'angle': {'units': 'data', 'field': 'angle'}, 'fill_color': {'value': 'gray'}, 'height': {'units': 'data', 'field': 'height'}, 'width': {'units': 'data', 'field': 'width'}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'type': 'rect'})
        self.test_rect.x = 50
        self.test_rect.y = 51
        self.test_rect.width = 100
        self.test_rect.height = 200
        self.test_rect.angle = 90
        self.assertEqual(self.test_rect.to_glyphspec(), {'line_color': {'value': 'black'}, 'angle': {'units': 'data', 'value': 90}, 'fill_color': {'value': 'gray'}, 'height': {'units': 'data', 'value': 200}, 'width': {'units': 'data', 'value': 100}, 'y': {'units': 'data', 'value': 51}, 'x': {'units': 'data', 'value': 50}, 'type': 'rect'})
Example #2
0
def jobtype_builder():
    jtypes = ["Half Time", "Full Time", "Hourly", "Temporary"]
    xdr = FactorRange(factors=jtypes)
    ydr = DataRange1d(sources=[source_jobtype.columns("data_range")])
    plot = Plot(title="Job Type",
                data_sources=[source_jobtype],
                x_range=xdr,
                y_range=ydr,
                plot_width=760,
                plot_height=500)
    xaxis = CategoricalAxis(plot=plot,
                            dimension=0,
                            major_label_orientation=pi / 4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    yaxis.major_tick_in = 0
    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
    quad = Rect(x="jobtypes",
                y="jobtype_half",
                height="count",
                width=0.9,
                fill_color="#33A6A4")
    bars = Glyph(data_source=source_jobtype,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#686975'
    return plot
Example #3
0
def weekday_builder():
    dow = [
        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
        "Sunday"
    ]
    xdr = FactorRange(factors=dow)
    ydr = DataRange1d(sources=[source_dow.columns("data_range")])
    plot = Plot(title="Weekday of Job Posting",
                data_sources=[source_dow],
                x_range=xdr,
                y_range=ydr,
                plot_width=760,
                plot_height=500)
    xaxis = CategoricalAxis(plot=plot,
                            dimension=0,
                            major_label_orientation=pi / 4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    yaxis.major_tick_in = 0
    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
    quad = Rect(x="weekday",
                y="weekday_half",
                height="count",
                width=0.9,
                fill_color="#D9301A")
    bars = Glyph(data_source=source_dow,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#686975'
    return plot
Example #4
0
def job_loc_plot_builder():
    xdr = FactorRange(factors=countries)
    ydr = DataRange1d(sources=[source_country.columns("data_range")])

    plot = Plot(title="Postings by Job Location (Country)",
                data_sources=[source_country],
                x_range=xdr,
                y_range=ydr,
                plot_width=760,
                plot_height=500)

    xaxis = CategoricalAxis(plot=plot,
                            dimension=0,
                            major_label_orientation=pi / 4.0)
    yaxis = LinearAxis(plot=plot, dimension=1)

    yaxis.major_tick_in = 0

    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)

    quad = Rect(x="country",
                y="count_half",
                height="count",
                width=0.9,
                fill_color="#483D8B")
    bars = Glyph(data_source=source_country,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=quad)
    plot.renderers.append(bars)
    plot.background_fill = '#333333'
    return plot
Example #5
0
 def make_punchcard_plot(self, source):
     xdr = FactorRange(factors=source.data["hours"][::7])
     ydr = FactorRange(factors=source.data["days"][:7])
     title = "%s punchcard" % self.modelform.installer
     plot = Plot(title=title,
                 data_sources=[source],
                 x_range=xdr,
                 y_range=ydr,
                 width=600,
                 height=400)
     rect = Rect(x="hours",
                 y="days",
                 width=1,
                 height=1,
                 fill_color="red",
                 fill_alpha="percentages")
     rect_glyph = Glyph(data_source=source,
                        xdata_range=xdr,
                        ydata_range=ydr,
                        glyph=rect)
     plot.renderers.append(rect_glyph)
     hover = HoverTool(plot=plot, tooltips=dict(downloads="@counts"))
     plot.tools.append(hover)
     xaxis = CategoricalAxis(plot=plot, dimension=0)
     yaxis = CategoricalAxis(plot=plot, dimension=1)
     return plot
Example #6
0
class TestRect(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Rect

        self.test_rect = Rect()

    def test_expected_properties(self):
        expected_properties = set(["x", "y", "width", "height", "angle"])
        actual_properties = get_prop_set(type(self.test_rect))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_rect.x, "x")
        self.assertEqual(self.test_rect.y, "y")
        self.assertEqual(self.test_rect.width, "width")
        self.assertEqual(self.test_rect.height, "height")
        self.assertEqual(self.test_rect.angle, "angle")
        self.assertEqual(self.test_rect.__view_model__, "rect")

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected["type"] = "rect"
        expected.update(
            {
                "angle": {"units": "data", "field": "angle"},
                "height": {"units": "data", "field": "height"},
                "width": {"units": "data", "field": "width"},
            }
        )
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
        self.test_rect.x = 50
        self.test_rect.y = 51
        self.test_rect.width = 100
        self.test_rect.height = 200
        self.test_rect.angle = 90
        expected.update(
            {
                "x": {"units": "data", "value": 50},
                "y": {"units": "data", "value": 51},
                "angle": {"units": "data", "value": 90},
                "height": {"units": "data", "value": 200},
                "width": {"units": "data", "value": 100},
            }
        )
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
Example #7
0
class TestRect(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Rect
        self.test_rect = Rect()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'width', 'height', 'angle'])
        actual_properties = get_prop_set(type(self.test_rect))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_rect.x, 'x')
        self.assertEqual(self.test_rect.y, 'y')
        self.assertEqual(self.test_rect.width, 'width')
        self.assertEqual(self.test_rect.height, 'height')
        self.assertEqual(self.test_rect.angle, 'angle')
        self.assertEqual(self.test_rect.__view_model__, 'rect')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected['type'] = 'rect'
        expected.update({
            'angle':  {'units': 'data', 'field': 'angle'},
            'height': {'units': 'data', 'field': 'height'},
            'width':  {'units': 'data', 'field': 'width'},
        })
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
        self.test_rect.x = 50
        self.test_rect.y = 51
        self.test_rect.width = 100
        self.test_rect.height = 200
        self.test_rect.angle = 90
        expected.update({
            'x':      {'units': 'data', 'value': 50},
            'y':      {'units': 'data', 'value': 51},
            'angle':  {'units': 'data', 'value': 90},
            'height': {'units': 'data', 'value': 200},
            'width':  {'units': 'data', 'value': 100},
        })
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
Example #8
0
def test_Rect():
    glyph = Rect()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.width == "width"
    assert glyph.height == "height"
    assert glyph.angle == "angle"
    assert glyph.dilate == False
    yield check_fill, glyph
    yield check_line, glyph
    yield check_props, glyph, ["x", "y", "width", "height", "angle",
                               "dilate"], FILL, LINE
Example #9
0
def make_box_violin_plot(data, maxwidth=0.9):
    """ 
    data: dict[Str -> List[Number]]
    maxwidth: float
        Maximum width of tornado plot within each factor/facet

    Returns the plot object 
    """
    print("Plotting box violin graph")
    plot_width = 500
    plot_height = 350
    df = pd.DataFrame(columns=["group", "width", "height", "texts", "cats"])
    bar_height = 50
    bins = [0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e10]
    # 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,
            width = np.log2(hist[1:]),
            height = np.ones(len(hist) - 1),
            texts = ["%d Nodes" % i for i in hist[1:-1]] + ["%d" % hist[-1]],
            cats = [">10^%d" % np.log10(bin) for bin in bins[1:-1]],
            )))
            
    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 = FactorRange(factors=list(df["cats"]))

    plot = Plot(data_sources=[ds], x_range=xdr, y_range=ydr,
                title="Degree Distribution (log scale)",
                plot_width=plot_width, plot_height=plot_height, 
                tools=[])
    yaxis = CategoricalAxis(plot=plot, location="left", axis_label="degree")
    plot.left.append(yaxis)
    
    glyph = Rect(x="group", y="cats", width="width", height="height",
                 fill_color="#3366ff")
    text_glyph = Text(x="group", y="cats", text="texts", text_baseline="middle",
                      text_align="center", angle=0)
    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
Example #10
0
def large_plot():
    source = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1]))

    xdr = Range1d(start=0, end=1)
    xdr.tags.append("foo")
    xdr.tags.append("bar")

    ydr = Range1d(start=10, end=20)
    ydr.tags.append("foo")

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

    ydr2 = Range1d(start=0, end=100)
    plot.extra_y_ranges = {"liny": ydr2}

    circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black")
    plot.add_glyph(source, circle, name="mycircle")

    line = Line(x="x", y="y")
    plot.add_glyph(source, line, name="myline")

    rect = Rect(x="x", y="y", width=1, height=1, fill_color="green")
    plot.add_glyph(source, rect, name="myrect")

    plot.add_layout(DatetimeAxis(), 'below')
    plot.add_layout(LogAxis(), 'left')
    plot.add_layout(LinearAxis(y_range_name="liny"), 'left')

    plot.add_layout(Grid(dimension=0), 'left')
    plot.add_layout(Grid(dimension=1), 'left')

    plot.add_tools(
        BoxZoomTool(),
        PanTool(),
        PreviewSaveTool(),
        ResetTool(),
        ResizeTool(),
        WheelZoomTool(),
    )

    return plot
Example #11
0
    ("DarkSlateGray",         "#2F4F4F", "Gray/Black"),
    ("Black",                 "#000000", "Gray/Black"),
], columns=["Name", "Color", "Group"])

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)))

plot = Plot(title="CSS3 Color Names", x_range=xdr, y_range=ydr, plot_width=600, plot_height=2000)

rect = Rect(x="groups", y="names", width=1, height=1, fill_color="colors", line_color=None)
plot.add_glyph(source, rect)

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

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

plot.add_layout(CategoricalAxis(), 'left')

doc = Document()
doc.add(plot)

if __name__ == "__main__":
    filename = "colors.html"
Example #12
0
 def setUp(self):
     from bokeh.glyphs import Rect
     self.test_rect = Rect()
Example #13
0
            y1="y",
            cx="xp01",
            cy="yp01",
            line_color="#4DAF4A",
            line_width=3)),
 ("ray",
  Ray(x="x",
      y="y",
      length=45,
      angle=-0.7,
      line_color="#FB8072",
      line_width=2)),
 ("rect",
  Rect(x="x",
       y="y",
       width=screen(10),
       height=screen(20),
       angle=-0.7,
       fill_color="#CAB2D6")),
 ("segment",
  Segment(x0="x",
          y0="y",
          x1="xm01",
          y1="ym01",
          line_color="#F4A582",
          line_width=3)),
 ("wedge",
  Wedge(x="x",
        y="y",
        radius=screen(15),
        start_angle=0.6,
        end_angle=4.1,
Example #14
0
 def setUp(self):
     from bokeh.glyphs import Rect
     self.test_rect = Rect()
Example #15
0
class TestRect(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Rect
        self.test_rect = Rect()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'width', 'height', 'angle'])
        actual_properties = get_prop_set(type(self.test_rect))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_rect.x, 'x')
        self.assertEqual(self.test_rect.y, 'y')
        self.assertEqual(self.test_rect.width, 'width')
        self.assertEqual(self.test_rect.height, 'height')
        self.assertEqual(self.test_rect.angle, 'angle')
        self.assertEqual(self.test_rect.__view_model__, 'rect')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected['type'] = 'rect'
        expected.update({
            'angle': {
                'units': 'data',
                'field': 'angle'
            },
            'height': {
                'units': 'data',
                'field': 'height'
            },
            'width': {
                'units': 'data',
                'field': 'width'
            },
        })
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
        self.test_rect.x = 50
        self.test_rect.y = 51
        self.test_rect.width = 100
        self.test_rect.height = 200
        self.test_rect.angle = 90
        expected.update({
            'x': {
                'units': 'data',
                'value': 50
            },
            'y': {
                'units': 'data',
                'value': 51
            },
            'angle': {
                'units': 'data',
                'value': 90
            },
            'height': {
                'units': 'data',
                'value': 200
            },
            'width': {
                'units': 'data',
                'value': 100
            },
        })
        self.assertEqual(self.test_rect.to_glyphspec(), expected)
Example #16
0
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