Exemple #1
0
    def plot(self, include, in_terminal=False):
        """
    Plot relevant variables in a flexible manner.

    Parameters
    ----------
    include : list
      The list of plots to include.
    in_terminal : bool, default=False
      If True, shows plots in terminal, giving an oldschool NASA vibe. If False, uses boring matplotlib. 
    """
        if in_terminal:
            import plotext as plt
        else:
            import matplotlib.pyplot as plt

        for plot in include:
            x_log = self.logs[plot['x']['logname']]
            x_data = x_log.get_data(plot['x']['ops'])

            y_log = self.logs[plot['y']['logname']]
            y_data = y_log.get_data(plot['y']['ops'])

            if in_terminal:
                plt.clear_plot()
                plt.nocolor()
                plt.figsize(75, 25)
            else:
                plt.figure()
            plt.plot(x_data, y_data)
            plt.show()
Exemple #2
0
 def plot_score_trace(self, t, R_scores):
     r = R_scores.shape[0]
     plt.clear_plot()
     plt.set_output_file(self._logfile)
     for i in range(self.g.p["mcmc"]["n_indep"]):
         if t < r:
             plt.scatter(R_scores[:t, i], label=str(i), line_color="red")
         else:
             plt.scatter(R_scores[np.r_[(t % r):r, 0:(t % r)], i],
                         label=str(i),
                         line_color="red")
     plt.figsize(80, 20)
     plt.ticks(4, 4)
     if t < 1000:
         xticks = [int(w * t) for w in np.arange(0, 1 + 1 / 3, 1 / 3)]
         xlabels = [str(round(x / 1000, 1)) + "k" for x in xticks]
     else:
         xticks = [0, 333, 666, 999]
         xlabels = [str(round((x + t) / 1000, 1)) + "k" for x in xticks]
     plt.xticks(xticks, xlabels)
     plt.canvas_color("none")
     plt.axes_color("none")
     plt.ticks_color("none")
     plt.show()
     print(file=self._logfile)
     self._logfile.flush()
Exemple #3
0
def plot_measures(measures, offset=0):
    start_timestamp = datetime.now() - timedelta(days=7)
    now = datetime.now()

    width, height = plt.terminal_size()

    if offset:
        height -= offset

    if MAXIMUM_HEIGHT and MAXIMUM_HEIGHT < height:
        height = MAXIMUM_HEIGHT

    if MAXIMUM_WIDTH and MAXIMUM_WIDTH < width:
        width = MAXIMUM_WIDTH

    values_y = [m.value for m in measures]
    values_x = [m.timestamp for m in measures]

    plt.clear_plot()
    plt.plot(values_x, values_y)
    plt.nocolor()

    xticks = [int(start_timestamp.strftime("%s"))]
    xlabels = [start_timestamp.strftime(DATETIME_FORMAT)]

    day = (start_timestamp + timedelta(days=1)).replace(hour=0,
                                                        minute=0,
                                                        second=0,
                                                        microsecond=0)

    while day < now:
        xticks.append(int(day.strftime("%s")))
        xlabels.append(day.strftime(DATETIME_FORMAT))

        day += timedelta(days=1)

    plt.xlim(int(start_timestamp.strftime("%s")), int(now.strftime("%s")))

    plt.xticks(xticks, xlabels)
    plt.figsize(width, height)

    plt.show()
Exemple #4
0
def diff2plot(diff, kind=None, title='Unnamed plot'):
    """Function to plot graph to the terminal. Can be scatter or bar plot (Initial test functionality)
    Works only with plotext 4.2, not above"""
    # try:
    #     import plotext as plt
    # except ModuleNotFoundError:
    #     # Error handling
    #     pass
    plx.clear_plot()
    diff = diff.round(2)
    if kind == 'bar':
        # expects a series with index being string names
        mask0 = (diff.values != 0) & ~_np.isnan(diff.values)
        if mask0.any():
            plx.bar(diff.index.values[mask0].tolist(),
                    diff.values[mask0].tolist(),
                    orientation="h",
                    width=0.3)
            plx.vertical_line(coordinate=0)
            plx.plotsize(100, diff.shape[0] * 2 + 3)
        else:
            return None
    else:
        mask0 = ((diff.values != 0) & ~_np.isnan(diff.values)).any(axis=0)
        if mask0.any():
            cols = diff.columns[mask0]
            x1 = plx.datetime.datetime_to_string(
                diff.index.astype('timedelta64[ns]') * 1000000000 +
                _J2000_ORIGIN)
            for i in range(cols.shape[0]):
                plx.scatter_date(x1,
                                 diff[cols[i]].to_list(),
                                 color=i,
                                 marker="hd",
                                 label=diff.columns[i])
                plx.plotsize(100, 30 + 3)
        else:
            return None

    plx.title(title)
    plx.limit_size(limit_xsize=False, limit_ysize=False)
    plx.show()
Exemple #5
0
    current_high = max(data["Close"].tolist())

    # y data will only show the most recent 10 hours of trades
    y = data["Close"].tail(600).tolist()

    # Current is the last index of all trades
    current = y[-1]

    # Show red or green chart if price has declined since opening
    if current >= opening:
        color = "green"
    else:
        color = "tomato"

    #For formating
    plt.clear_plot()
    plt.clear_terminal()

    plt.scatter(y,
                point_color=color,
                fill=True,
                label=ticker + "- Open:" + str(opening) + " Current:" +
                str(current) + "1d High:" +
                str(current_high))  # Labled as Open: , Current: , High:

    #Most recent hours of trades will be highlighted blue
    plt.scatter(list(range(540, 600)),
                y[-60:],
                fill=True,
                label="Current Hour",
                point_color="blue")