Beispiel #1
0
def test_plot_if_title_is_converted_from_string_to_Title() -> None:
    plot = Plot()
    plot.title = "A title"
    plot.title.text_color = "olive"
    assert isinstance(plot.title, Title)
    assert plot.title.text == "A title"
    assert plot.title.text_color == "olive"
Beispiel #2
0
def get_weather_plot(time_int=None, t_min=None, t_max=None):
    plot_height = cs.plot_height
    plot_width = cs.plot_width
    border_left = cs.border_left
    column_names = cs.column_names_weewx
    column_time = cs.time_column_name_weewx
    if t_max == None or t_min == None:
        t_max, t_min = get_first_time_interval()
    t_span = t_max - t_min
    if time_int == None:
        time_int = cs.time_int
    data_seconds = sql_con.get_data_ws(time_int=time_int,
                                       t_min=t_min,
                                       t_max=t_max)
    data_seconds.iloc[:, 0] = data_seconds.iloc[:, 0] * 1000

    plot = Plot(
        x_range=DataRange1d(start=(t_min - t_span * .1) * 1000,
                            end=(t_max + t_span * .1) * 1000),
        y_range=DataRange1d(),
        plot_width=plot_width,
        plot_height=plot_height,
        # x_axis_type="datetime",
        min_border_left=border_left,
        toolbar_location="right")

    add_glyphs_to_plot(column_names, column_time, data_seconds, plot,
                       'source_weather')

    plot.add_layout(DatetimeAxis(name="date_time_axis"), 'below')

    plot.add_tools(
        PanTool(),
        WheelZoomTool(),
        # ResizeTool(),
        CrosshairTool(),
        PreviewSaveTool())
    Grid(plot=plot,
         dimension=0,
         ticker=plot.select('date_time_axis')[0].ticker)

    Grid(plot=plot,
         dimension=1,
         ticker=plot.select(type=LinearAxis, name=column_names[0])[0].ticker)

    set_legends(plot)

    plot.title = cs.plot_title_weewx + ' averaged to {} seconds'.format(
        time_int)

    return plot
Beispiel #3
0
def get_weather_plot(time_int=None,t_min=None,t_max=None):
    plot_height = cs.plot_height
    plot_width = cs.plot_width
    border_left = cs.border_left
    column_names = cs.column_names_weewx
    column_time = cs.time_column_name_weewx
    if t_max == None or t_min == None:
        t_max, t_min = get_first_time_interval()
    t_span = t_max - t_min
    if time_int == None:
        time_int = cs.time_int
    data_seconds = sql_con.get_data_ws(time_int=time_int, t_min=t_min, t_max=t_max)
    data_seconds.iloc[:, 0] = data_seconds.iloc[:, 0] * 1000

    plot = Plot(x_range=DataRange1d(start=(t_min-t_span*.1)*1000,
                                    end=(t_max+t_span*.1)*1000),
                y_range=DataRange1d(),
                plot_width=plot_width,
                plot_height=plot_height,
                # x_axis_type="datetime",
                min_border_left=border_left,
                toolbar_location="right")

    add_glyphs_to_plot(column_names, column_time, data_seconds, plot,'source_weather')

    plot.add_layout(DatetimeAxis(name="date_time_axis"), 'below')

    plot.add_tools(PanTool(),
                   WheelZoomTool(),
                   # ResizeTool(),
                   CrosshairTool(),
                   PreviewSaveTool()
                   )
    Grid(plot=plot,dimension=0,ticker=plot.select('date_time_axis')[0].ticker)

    Grid(plot=plot,
         dimension=1,
         ticker=plot.select(type=LinearAxis,name=column_names[0])[0].ticker
         )

    set_legends(plot)

    plot.title = cs.plot_title_weewx + ' averaged to {} seconds'.format(time_int)


    return plot
Beispiel #4
0
    def __init__(self, total: int, title: str, color: str,
                 bokeh_session: object):
        """
        Initialize a ProgressBar instance.
        :param total: number of steps the progress bar is divided into. In other words, the number of times update should be called.
        :param title: the title of the progress bar
        :param color: the color of the progress bar
        :param bokeh_session: bokeh server session
        """
        self.color = color
        self.title = title
        self.total = total
        self.current_source_index = 0
        self.source = self.create_column_data_source()

        plot = Plot(plot_width=1000,
                    plot_height=50,
                    min_border=0,
                    toolbar_location=None,
                    outline_line_color=None)

        glyph = Rect(x="x_coordinate",
                     y=0,
                     width=1,
                     height=1,
                     angle=-0.0,
                     fill_color="color",
                     line_color="color",
                     line_alpha=0.3,
                     fill_alpha=0.3)

        plot.add_glyph(self.source, glyph)

        self.title_object = Title()
        self.title_object.text = "     " + self.title
        plot.title = self.title_object

        bokeh_session.document.add_root(plot)
x = np.linspace(1, 5, 100)
y = x + np.sin((x - 1) * np.pi)
x2 = np.linspace(1.5, 5.5, 5)
z = x2 + 2 * np.cos((x2 - 1) * np.pi)

source1 = ColumnDataSource({
    "x": [1, 2, 3, 4, 5],
    "y": [1, 2, 3, 4, 5],
    "who": ["a", "b", "c", "d", "e"]
})
source2 = ColumnDataSource({"x": x, "y": y})
source3 = ColumnDataSource({"x": x2, "y": z})
source4 = ColumnDataSource({"y": [2.5], "x": [0.5]})

plot = Plot(width=300, height=300)
plot.title = Title(text="Themed glyphs")

xaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter())
yaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter())
plot.add_layout(xaxis, "below")
plot.add_layout(yaxis, "left")

plot.add_glyph(source1, Scatter(x="x", y="y", marker="diamond", size=20))
plot.add_glyph(source1, Text(x=dodge("x", -0.2), y=dodge("y", 0.1),
                             text="who"))
plot.add_glyph(source2, Line(x="x", y="y"))
plot.add_glyph(source3, Ellipse(x="x",
                                y="y",
                                width=0.2,
                                height=0.3,
                                angle=-0.7))
    def tweets_per_hour_plot(self, data_path, emotion=None, color="#b3de69"):
        #data_path = os.path.dirname(__file__) + "/../data/pbFollowers/merged/"
        data_path = data_path + "merged/"
        dir_files = os.listdir(data_path)

        counts_of_tweets = {}

        for filename in dir_files:
            #df = pd.read_json(data_path + filename)
            df = self.get_flattened_data(data_path + filename, 'tones',
                                         ['user', 'created_at'])
            if emotion is not None:
                try:
                    df = df[df.tone_name == emotion]
                except AttributeError:
                    continue
            try:
                df['created_at'] = df['created_at'] / 1000
            except TypeError:
                print("\'Created_at\' error where it is somehow a dict")
                continue
            offset = 0
            try:
                offset = df['user'][0]['utc_offset']
            except (IndexError, KeyError):
                offset = 0
            if offset is None:
                offset = 0
            #df['std_time'] = df['created_at'] + pd.TimedeltaIndex(df['offset'], unit='s')
            df['std_time'] = df['created_at'] + offset
            df['std_time'] = [
                datetime.datetime.fromtimestamp(x) for x in df['std_time']
            ]
            df = df.set_index(df['std_time'])
            temp = pd.DatetimeIndex(df['std_time'])
            df['hour'] = temp.hour
            p = df.groupby(df['hour'])
            freq_of_tweets = p['std_time'].count()
            freq_dict = freq_of_tweets.to_dict()
            for key, value in freq_dict.items():
                try:
                    counts_of_tweets[key] += value
                except KeyError:
                    counts_of_tweets[key] = value

        hours = np.fromiter(counts_of_tweets.keys(), dtype=float)
        hours += 1
        numTweets = np.fromiter(counts_of_tweets.values(), dtype=float)

        # output to static HTML file
        if emotion is None:
            hourly_freq_plot_path = data_path + "../plots/Hourly_freq_plot.html"
            output_file(hourly_freq_plot_path)

        source = ColumnDataSource(data=dict(hours=hours, numTweets=numTweets))

        hover = HoverTool(tooltips=[
            ('hours', '@hours'),
            ('numTweets', '@numTweets'),
        ])

        xdr = DataRange1d()
        ydr = DataRange1d()
        plot = Plot(x_range=xdr,
                    y_range=ydr,
                    plot_width=500,
                    plot_height=500,
                    h_symmetry=False,
                    v_symmetry=False,
                    min_border=0,
                    tools=[hover])

        glyph = VBar(x="hours",
                     top="numTweets",
                     bottom=0,
                     width=0.5,
                     fill_color=color)
        plot.add_glyph(source, glyph)

        xaxis = LinearAxis()
        plot.add_layout(xaxis, 'below')

        yaxis = LinearAxis()
        plot.add_layout(yaxis, 'left')

        t = Title()
        if emotion is not None:
            t.text = "(" + emotion + ") Number of Tweets by Hour"
        else:
            t.text = "(all emotions) Number of Tweets by Hour"
        plot.title = t
        plot.xaxis.axis_label = 'Hours'
        plot.yaxis.axis_label = 'Number of Tweets'

        if emotion is not None:
            return plot
        else:
            show(plot)
            return plot