Beispiel #1
0
def create_bar_chart(data,
                     title,
                     x_name,
                     y_name,
                     hover_tool=None,
                     width=1100,
                     height=400):
    """Creates a bar chart plot with the exact styling for the centcom
       dashboard. Pass in data as a dictionary, desired plot title,
       name of x axis, y axis and the hover tool HTML.
    """
    source = ColumnDataSource(data)
    xdr = FactorRange(factors=list(data[x_name]))
    ydr = Range1d(start=0, end=max(data[y_name]) * 1.05)

    tools = []
    if hover_tool:
        tools = [
            hover_tool,
        ]

    plot = figure(title=title,
                  x_range=xdr,
                  y_range=ydr,
                  plot_width=width,
                  plot_height=height,
                  min_border=0,
                  toolbar_location="above",
                  tools=tools,
                  outline_line_color="#666666")

    glyph = VBar(x=x_name,
                 top=y_name,
                 bottom=0,
                 width=.8,
                 fill_color="#ffdf00")
    plot.add_glyph(source, glyph)
    plot.add_tools(WheelZoomTool())
    plot.add_tools(BoxZoomTool())
    plot.add_tools(ZoomOutTool())

    xaxis = LinearAxis()
    yaxis = LinearAxis()

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
    plot.toolbar.logo = None
    plot.min_border_top = 0
    plot.xgrid.grid_line_color = None
    plot.ygrid.grid_line_color = "#999999"
    plot.yaxis.axis_label = "Weight"
    plot.ygrid.grid_line_alpha = 0.1
    plot.xaxis.axis_label = "Grouping"
    plot.xaxis.major_label_orientation = 1
    return plot
Beispiel #2
0
    def __init__(self, dataset, parameters):

        self.dataset = dataset

        # Set up the controls
        self.specials = Selector(
            name="Specials",
            kind="specials",
            css_classes=["specials"],
            entries={
                "Color-magnitude diagram": "cmd",
                "Period vs. radius": "pr",
                "Period vs. transit duration": "pdt",
            },
            default="Color-magnitude diagram",
        )
        self.data = Selector(
            name="Datasets",
            kind="datasets",
            css_classes=["data"],
            entries={"TOI Catalog": "toi", "Confirmed Planets": "confirmed"},
            default="Confirmed Planets",
        )
        self.xaxis = Selector(
            name="Build-Your-Own",
            kind="parameters",
            css_classes=["build-your-own"],
            entries=parameters,
            default="ra",
            title="X Axis",
        )
        self.yaxis = Selector(
            kind="parameters",
            css_classes=["build-your-own"],
            entries=parameters,
            default="dec",
            title="Y Axis",
        )
        self.size = Selector(
            name="Sides",
            kind="parameters",
            css_classes=["sides"],
            entries=parameters,
            default="dist",
            title="Marker Size",
            none_allowed=True,
        )
        self.color = Selector(
            kind="parameters",
            css_classes=["sides"],
            entries=parameters,
            default="dist",
            title="Marker Color",
            none_allowed=True,
        )

        # Set up the plot
        self.source = ColumnDataSource(
            data=dict(x=[], y=[], size=[], color=[])
        )
        self.plot = figure(
            plot_height=600,
            plot_width=700,
            title="",
            tooltips=[("TIC ID", "@ticid")],
            sizing_mode="scale_both",
        )
        self.plot.circle(
            x="x",
            y="y",
            source=self.source,
            size="size",
            color=linear_cmap(
                field_name="color", palette=Viridis256, low=0, high=1
            ),
            line_color=None,
        )
        self.plot.add_tools(
            BoxSelectTool(),
            BoxZoomTool(),
            LassoSelectTool(),
            PanTool(),
            PolySelectTool(),
            TapTool(),
            WheelZoomTool(),
            WheelPanTool(),
            ZoomInTool(),
            ZoomOutTool(),
            HoverTool(),
            CrosshairTool(),
            ResetTool(),
        )

        # Register the callback
        for control in [
            self.specials,
            self.data,
            self.xaxis,
            self.yaxis,
            self.size,
            self.color,
        ]:
            control.widget.on_change("value", self.callback)

        # Load and display the data
        self.callback(None, None, None)
Beispiel #3
0
def create_NAM_graph(df):
    source = ColumnDataSource(df)
    # Create plot 1
    y_overlimit = 0.05
    p1 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    if len(df) > 65:
        p1.title.text = '10 Day Temperature'
    else:
        p1.title.text = '3.5 Day Temperature'
    p1.xaxis.axis_label = 'Date/Time'
    p1.yaxis.axis_label = 'Temperature \N{DEGREE SIGN}C'
    # add lines
    glyph_1 = p1.line(x='DATETIME',
                      y='TMP',
                      source=source,
                      color='OrangeRed',
                      line_width=1.5)
    glyph_1a = p1.scatter(x='DATETIME',
                          y='TMP',
                          source=source,
                          line_color="darkRed",
                          fill_color="OrangeRed",
                          size=4)
    p1.y_range = Range1d(df['TMP'].min() * (1 - y_overlimit),
                         df['TMP'].max() * (1 + y_overlimit))
    # SECOND AXIS
    y_column2_range = "HGT_0C_DB" + "_range"
    p1.extra_y_ranges = {
        y_column2_range:
        Range1d(start=df['HGT_0C_DB'].min() * (1 - y_overlimit),
                end=df['HGT_0C_DB'].max() * (1 + y_overlimit))
    }
    p1.add_layout(
        LinearAxis(y_range_name=y_column2_range, axis_label='Elevation (m)'),
        "right")
    # add lines
    glyph_2 = p1.line(x='DATETIME',
                      y="HGT_0C_DB",
                      source=source,
                      line_width=1.5,
                      y_range_name=y_column2_range,
                      color="gold")
    glyph_2a = p1.scatter(x='DATETIME',
                          y='HGT_0C_DB',
                          source=source,
                          y_range_name=y_column2_range,
                          line_color="goldenrod",
                          fill_color="gold",
                          size=4)
    # tools
    hover1a = HoverTool(renderers=[glyph_1],
                        tooltips=[('\N{DEGREE SIGN}C', '@TMP'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    hover1b = HoverTool(renderers=[glyph_2],
                        tooltips=[('m', '@HGT_0C_DB'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    p1.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p1.toolbar.logo = None
    p1.toolbar.active_drag = None
    p1.toolbar.active_scroll = None
    p1.toolbar.active_tap = None
    p1.add_tools(hover1a, hover1b)
    # legend 1
    legend = Legend(items=[("Temp", [glyph_1, glyph_1a]),
                           ("Frz Lvl", [glyph_2, glyph_2a])],
                    location="center",
                    orientation="horizontal")
    p1.add_layout(legend, 'below')
    # create tab from plot
    tab1 = Panel(child=p1, title="Temperature")
    # create plot 2
    p2 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    if len(df) > 65:
        p2.title.text = '10 Day Precipitation'
    else:
        p2.title.text = '3.5 Day Precipitation'
    p2.xaxis.axis_label = 'Date/Time'
    p2.yaxis.axis_label = 'Amount (mm/cm)'
    # add lines
    glyph_1 = p2.line(x='DATETIME',
                      y='RQP',
                      source=source,
                      color='blue',
                      line_width=1.5)
    glyph_1a = p2.scatter(x='DATETIME',
                          y='RQP',
                          source=source,
                          line_color="darkblue",
                          fill_color="blue",
                          size=4)
    glyph_2 = p2.line(x='DATETIME',
                      y='SQP',
                      source=source,
                      color='lavender',
                      line_width=1.5)
    glyph_2a = p2.scatter(x='DATETIME',
                          y='SQP',
                          source=source,
                          line_color="lightsteelblue",
                          fill_color="lavender",
                          size=4)
    p2.varea(x='DATETIME',
             y1='SQP',
             source=source,
             color='GhostWhite',
             alpha=0.5)
    band = Band(base='DATETIME',
                upper='RQP',
                source=source,
                level='overlay',
                fill_alpha=0.3,
                fill_color='SkyBlue')
    p2.add_layout(band)
    # tools
    hover2a = HoverTool(renderers=[glyph_1],
                        tooltips=[('mm Rain', '@RQP'),
                                  ('mm Freezing Rain', '@FQP'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    hover2b = HoverTool(renderers=[glyph_2],
                        tooltips=[('cm Snow', '@SQP'), ('mm Ice/Hail', '@IQP'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    p2.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p2.toolbar.logo = None
    p2.toolbar.active_drag = None
    p2.toolbar.active_scroll = None
    p2.toolbar.active_tap = None
    p2.add_tools(hover2a, hover2b)
    # legend 2
    legend = Legend(items=[("Rain", [glyph_1, glyph_1a]),
                           ("Snow", [glyph_2, glyph_2a])],
                    location="center",
                    orientation="horizontal")
    p2.add_layout(legend, 'below')
    # create tab from plot
    tab2 = Panel(child=p2, title="Precipitation")
    # plot 3
    p3 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    if len(df) > 65:
        p1.title.text = '10 Day Wind/Cloud'
    else:
        p1.title.text = '3.5 Day Wind/Cloud'
    p3.xaxis.axis_label = 'Date/Time'
    p3.yaxis.axis_label = 'Speed (km/h) / % Coverage'
    # add lines
    glyph_1 = p3.line(x='DATETIME',
                      y='WS',
                      source=source,
                      color='green',
                      line_width=1.5)
    glyph_1a = p3.scatter(x='DATETIME',
                          y='WS',
                          source=source,
                          line_color="darkgreen",
                          fill_color="green",
                          size=4)
    glyph_2 = p3.line(x='DATETIME',
                      y='CLOUD',
                      source=source,
                      color='grey',
                      line_width=1.5)
    glyph_2a = p3.scatter(x='DATETIME',
                          y='CLOUD',
                          source=source,
                          line_color="darkgrey",
                          fill_color="grey",
                          size=4)
    band = Band(base='DATETIME',
                upper='CLOUD',
                source=source,
                level='underlay',
                fill_alpha=0.3,
                fill_color='lightgrey')
    p3.add_layout(band)
    # tools
    hover3a = HoverTool(renderers=[glyph_1],
                        tooltips=[('Wind Speed', '@WS'),
                                  ('Wind Direction', '@WD'), ('Gusts', '@WG'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    hover3b = HoverTool(renderers=[glyph_2],
                        tooltips=[('% Coverage', '@CLOUD'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    p3.toolbar.logo = None
    p3.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p3.toolbar.active_drag = None
    p3.toolbar.active_scroll = None
    p3.toolbar.active_tap = None
    p3.add_tools(hover3a, hover3b)
    # legend 3
    legend = Legend(items=[("Wind", [glyph_1, glyph_1a]),
                           ("Cloud", [glyph_2, glyph_2a])],
                    location="center",
                    orientation="horizontal")
    p3.add_layout(legend, 'below')
    # tab from plot
    tab3 = Panel(child=p3, title="Wind/Cloud")
    # merge tabs into one plot
    plot = Tabs(tabs=[tab1, tab2, tab3])
    # return plot
    html = file_html(plot, CDN)
    return html
Beispiel #4
0
def create_HRDPS_graph(df):
    source = ColumnDataSource(df)
    # create plot 1
    p1 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    p1.title.text = '48H Temperature'
    p1.xaxis.axis_label = 'Date/Time'
    p1.yaxis.axis_label = 'Temperature \N{DEGREE SIGN}C'
    # add lines
    glyph_1 = p1.line(x='DATETIME',
                      y='TMP',
                      source=source,
                      color='OrangeRed',
                      line_width=1.5)
    glyph_1a = p1.scatter(x='DATETIME',
                          y='TMP',
                          source=source,
                          line_color="darkRed",
                          fill_color="OrangeRed",
                          size=4)
    # tools
    hover1 = HoverTool(renderers=[glyph_1],
                       tooltips=[('\N{DEGREE SIGN}C', '@TMP'),
                                 ('Time', '@DATETIME{%F %T}')],
                       formatters={'@DATETIME': 'datetime'},
                       mode='vline')
    p1.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p1.toolbar.logo = None
    p1.toolbar.active_drag = None
    p1.toolbar.active_scroll = None
    p1.toolbar.active_tap = None
    p1.add_tools(hover1)
    # legend 1
    legend = Legend(items=[("Temp", [glyph_1, glyph_1a])],
                    location="center",
                    orientation="horizontal")
    p1.add_layout(legend, 'below')
    # create tab from plot
    tab1 = Panel(child=p1, title="Temperature")
    # create plot 2
    p2 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    p2.title.text = '48H Precipitation'
    p2.xaxis.axis_label = 'Date/Time'
    p2.yaxis.axis_label = 'Amount (mm/cm)'
    # Add lines
    glyph_1 = p2.line(x='DATETIME',
                      y='RQP',
                      source=source,
                      color='blue',
                      line_width=1.5)
    glyph_1a = p2.scatter(x='DATETIME',
                          y='RQP',
                          source=source,
                          line_color="darkblue",
                          fill_color="blue",
                          size=4)
    glyph_2 = p2.line(x='DATETIME',
                      y='SQP',
                      source=source,
                      color='lavender',
                      line_width=1.5)
    glyph_2a = p2.scatter(x='DATETIME',
                          y='SQP',
                          source=source,
                          line_color="lightsteelblue",
                          fill_color="lavender",
                          size=4)
    p2.varea(x='DATETIME',
             y1='SQP',
             source=source,
             color='GhostWhite',
             alpha=0.5)
    band = Band(base='DATETIME',
                upper='RQP',
                source=source,
                level='overlay',
                fill_alpha=0.3,
                fill_color='SkyBlue')
    p2.add_layout(band)
    # tools
    hover2a = HoverTool(renderers=[glyph_1],
                        tooltips=[('mm Rain', '@RQP'),
                                  ('mm Freezing Rain', '@FQP'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    hover2b = HoverTool(renderers=[glyph_2],
                        tooltips=[('cm Snow', '@SQP'), ('mm Ice/Hail', '@IQP'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    p2.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p2.toolbar.logo = None
    p2.toolbar.active_drag = None
    p2.toolbar.active_scroll = None
    p2.toolbar.active_tap = None
    p2.add_tools(hover2a, hover2b)
    # legend 2
    legend = Legend(items=[("Rain", [glyph_1, glyph_1a]),
                           ("Snow", [glyph_2, glyph_2a])],
                    location="center",
                    orientation="horizontal")
    p2.add_layout(legend, 'below')
    # Create tab from plot
    tab2 = Panel(child=p2, title="Precipitation")
    # create plot 3
    p3 = figure(x_axis_type='datetime',
                plot_width=600,
                plot_height=400,
                toolbar_location='above',
                sizing_mode='scale_width')
    p3.title.text = '48H Wind/Cloud'
    p3.xaxis.axis_label = 'Date/Time'
    p3.yaxis.axis_label = 'Speed (km/h) / % Coverage'
    # Add lines
    glyph_1 = p3.line(x='DATETIME',
                      y='WS',
                      source=source,
                      color='green',
                      line_width=1.5)
    glyph_1a = p3.scatter(x='DATETIME',
                          y='WS',
                          source=source,
                          line_color="darkgreen",
                          fill_color="green",
                          size=4)
    glyph_2 = p3.line(x='DATETIME',
                      y='CLOUD',
                      source=source,
                      color='grey',
                      line_width=1.5)
    glyph_2a = p3.scatter(x='DATETIME',
                          y='CLOUD',
                          source=source,
                          line_color="darkgrey",
                          fill_color="grey",
                          size=4)
    band = Band(base='DATETIME',
                upper='CLOUD',
                source=source,
                level='underlay',
                fill_alpha=0.3,
                fill_color='lightgrey')
    p3.add_layout(band)
    # tools
    hover3a = HoverTool(renderers=[glyph_1],
                        tooltips=[('Wind Speed', '@WS'),
                                  ('Wind Direction', '@WD'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    hover3b = HoverTool(renderers=[glyph_2],
                        tooltips=[('% Coverage', '@CLOUD'),
                                  ('Time', '@DATETIME{%F %T}')],
                        formatters={'@DATETIME': 'datetime'},
                        mode='vline')
    p3.tools = [ZoomInTool(), ZoomOutTool(), PanTool(), ResetTool()]
    p3.toolbar.logo = None
    p3.toolbar.active_drag = None
    p3.toolbar.active_scroll = None
    p3.toolbar.active_tap = None
    p3.add_tools(hover3a, hover3b)
    # legend 3
    legend = Legend(items=[("Wind", [glyph_1, glyph_1a]),
                           ("Cloud", [glyph_2, glyph_2a])],
                    location="center",
                    orientation="horizontal")
    p3.add_layout(legend, 'below')
    # Create tab from plot
    tab3 = Panel(child=p3, title="Wind/Cloud")
    # merge to final plot
    plot = Tabs(tabs=[tab1, tab2, tab3])
    # return graph
    html = file_html(plot, CDN)
    return html
        TableColumn(field="koi_score",
                    title="Disp Score",
                    formatter=NumberFormatter(format="0.00"))
    ]
    # Make the bokeh data table
    data_table = DataTable(source=source,
                           columns=columns,
                           height=300,
                           width=1000)

    # Do the Figure initially it is log period vs log planet radius
    # Include hovertool
    hover = HoverTool(tooltips=[("KOI", "@koi_number{0.00}")])

    data_figure = figure(height=600, width=1000,x_axis_label='Log Period [Day]', \
                    y_axis_label='Log Rp [Rearth]', tools=[hover, TapTool(), BoxZoomTool(), PanTool(), ZoomOutTool(), ZoomInTool(), ResetTool(), SaveTool()])
    data_figure.axis.axis_line_width = 3
    circle_handle = data_figure.circle(x='Logkoi_period',
                                       y='Logkoi_prad',
                                       source=source,
                                       size=10)
    data_figure.axis.axis_label_text_font_size = "20pt"
    data_figure.axis.major_label_text_font_size = "15pt"
    data_figure.axis.major_tick_line_width = 3
    xAxisHandle = data_figure.axis[0]
    yAxisHandle = data_figure.axis[1]
    # Include tap tool to open url with click on point
    taptool = data_figure.select(type=TapTool)
    taptool.callback = OpenURL(url="@koi_url")

    # START JAVASCRIPT literal code for handling figure data axis change