コード例 #1
0
def show_points(
    points: t.Sequence[t.Tuple[datetime.datetime, t.Union[int, float]]],
    title: str,
    y_label: str,
) -> None:
    if not points:
        print('No data')
        return

    import plotext as plt

    dates, values = zip(*points)
    date_time_stamps = [d.timestamp() for d in dates]

    plt.plot(date_time_stamps, values)
    plt.xticks(date_time_stamps, (d.strftime('%Y/%m/%d') for d in dates))
    plt.title(title)
    plt.xlabel('Date')
    plt.ylabel(y_label)
    plt.ylim(0, max(values) * 1.1)
    plt.canvas_color('iron')
    plt.axes_color('cloud')
    plt.grid(False, True)

    plt.show()
コード例 #2
0
    def plot_coverage(self, sequence_name, coverage, num_bins=100):
        try:
            import plotext as plt
        except:
            self.run.warning(
                "You don't have the `plotext` library to plot data :/ You can "
                "install it by running `pip install plotext` in your anvi'o "
                "environment.",
                header="NO PLOT FOR YOU :(")

            return

        plt.clp()
        plt.title(f"{sequence_name}")
        plt.xlabel("Position")
        plt.ylabel("Coverage")
        plt.plot(coverage, fillx=True)
        plt.plotsize(self.progress.terminal_width, 25)
        plt.canvas_color("cloud")
        plt.axes_color("cloud")
        plt.ticks_color("iron")

        try:
            plt.show()
        except OSError:
            self.run.warning(
                "Redirecting things into files and working with funny TTYs confuse "
                "the plotting services. Is ok tho.",
                header="NO PLOT FOR YOU :(")
            pass
def plot_terminal(data, title, xtitle):
    """
    Plot data to the terminal using plotext
    """
    import plotext as plt
    x = data.index.tolist()
    y = data[title].tolist()

    plt.scatter(x, y)
    plt.title(title)
    plt.xlabel(xtitle)
    plt.plot_size(100, 30)
    plt.show()
コード例 #4
0
def main(filea, fileb):

    if filea is None:
        # take the second most recent
        profiling_files = parse_and_sort_profiling_files()
        filea = profiling_files[-2]

    if fileb is None:
        # take the most recent
        profiling_files = parse_and_sort_profiling_files()
        fileb = profiling_files[-1]

    profile_a = pd.read_pickle(filea)
    profile_b = pd.read_pickle(fileb)

    merged = pd.merge(
        profile_a, 
        profile_b, 
        how='left',
        on=['document_length','document_depth', 'working_depth', 'item_length']
    )


    plt.clp()
    bins = 30
    plt.hist(merged['tottime_x'], bins, label="profile a")
    plt.hist(merged['tottime_y'], bins, label="profile b")
    plt.title("tottime distribution")
    plt.xlabel("time bins")
    plt.ylabel("frequency")
    plt.canvas_color("none")
    plt.axes_color("none")
    plt.ticks_color("cloud")
    plt.figsize(50, 15)
    plt.show()

    merged['diff'] = merged['tottime_x'] - merged['tottime_y']
    print("")
    print(f"## avg improvement: {merged['diff'].mean()} seconds ##")
    print("")
コード例 #5
0
'''
small auxiliary script that uses the lammps log parser to quickly plot data
to terminal

usage:
plot_thermo.py <thermo_key>
'''

import lammps_log_parser as lmp
import plotext as pt
import sys

yvar = sys.argv[1]

data = lmp.parse_log_to_pandas_df('*log')
pt.plot(data['Step'], data[yvar])

pt.xlabel('simulation steps')
pt.ylabel(yvar)
pt.nocolor()
pt.figsize(160, 40)

pt.show()
コード例 #6
0
def build_axes(time_series):
    count_by_month = Counter(
        [note.strftime("%b %Y") for note in sorted(time_series)])
    x_axis = []
    y_axis = []
    for date, count in count_by_month.items():
        x_axis.append(date)
        y_axis.append(count)
    return x_axis, y_axis


def plotter(x, y, foreground_color, background_color):
    plt.datetime.set_datetime_form(date_form="%b %Y")
    plt.plot_date(x, y, marker="dot", color=foreground_color)
    plt.ticks_color(foreground_color)
    plt.plotsize(88, 30)
    plt.canvas_color(background_color)
    plt.axes_color(background_color)


if __name__ == "__main__":
    notes = parse_notes()
    x_axis, y_axis = build_axes(notes)
    print(f"\nYour Zettelkasten contains [b]{len(notes)}[/b] notes.\n\n")
    plt.clp()
    plotter(x_axis, y_axis, "black", "yellow")
    plt.title("Notes Written Per Month")
    plt.xlabel("Date")
    plt.show()
コード例 #7
0
def show_statistics(rule_file=None, rule_set=None, indx=None):
    interface = None
    if rule_set == "-e":
        interface = "external"
    elif rule_set == "-i":
        interface = "internal"
    logs = utils.load_logs('logs.json')
    print("")
    print("-" * 13, "OVERALL FIREWALL STATISTICS", "-" * 13)
    print("TOTAL PACkETS RECEIVED BY THE FIREWALL: ", logs["total_packets"])
    print("TOTAL PACkETS DROPPED BY THE FIREWALL: ", logs["total_dropped"])
    if rule_file != None:
        if interface != None:
            print("")
            print("-" * 12, interface.upper(), "INTERFACE STATISTICS",
                  "-" * 12)
            print("TOTAL PACKETS RECEIVED ON", interface.upper(),
                  "INTERFACE: ", logs[rule_file][interface]["total_packets"])
            print("TOTAL PACKETS DROPPED ON", interface.upper(), "INTERFACE: ",
                  logs[rule_file][interface]["total_dropped"])
            if indx != None:
                if indx in logs[rule_file][interface]:
                    print("\nTOTAL PACKETS DROPPED DUE TO RULE", indx, "ON",
                          interface.upper(), "INTERFACE :",
                          logs[rule_file][interface][indx])
                else:
                    print("Invalid rule index!")
        else:
            print("")
            print("-" * 12, "EXTERNAL INTERFACE STATISTICS", "-" * 12)
            print("TOTAL PACKETS RECEIVED ON EXTERNAL INTERFACE: ",
                  logs[rule_file]["external"]["total_packets"])
            print("TOTAL PACKETS DROPPED ON EXTERNAL INTERFACE: ",
                  logs[rule_file]["external"]["total_dropped"])
            print("")
            print("-" * 12, "INTERNAL INTERFACE STATISTICS", "-" * 12)
            print("TOTAL PACKETS RECEIVED ON INTERNAL INTERFACE: ",
                  logs[rule_file]["internal"]["total_packets"])
            print("TOTAL PACKETS DROPPED ON INTERNAL INTERFACE: ",
                  logs[rule_file]["internal"]["total_dropped"])
    else:
        print("")
        print("-" * 16, "ICMP FLOOD STATISTICS", "-" * 16)
        print("FLOODS ENCOUNTERED SO FAR: ", logs["icmp_floods"])
        print("PACKETS DROPPED DURING ICMP BLOCK:", logs["icmp_dropped"])
        print("")
        print("-" * 22, "PPS INFO", "-" * 22)
        print("MAXIMUM PPS SO FAR: ", logs["max_pps"])
        print("")
        title = "-" * 18 + "NETWORK TRAFFIC" + "-" * 18
        net_traffic = logs["traffic"]
        max_sec = max(np.array(list(net_traffic.keys())).astype(int))
        packets_num = np.zeros(max_sec + 1)
        for i in net_traffic:
            packets_num[int(i)] = net_traffic[i]
        packets_num = packets_num.astype(int)
        plt.scatter(np.arange(max_sec + 1), packets_num, fillx=True)
        plt.figsize(80, 20)
        plt.title(title)
        plt.xlabel("Time")
        plt.ylabel("Packets")
        plt.show()