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 print_plot(items, x, y=None, sort=None, fillx=False, title=None, grid=False, marker=None, color=None, background_color=None, axes_color=None): df = items_to_dataframe(items, sort=sort) x_list = df[x].tolist() y_list = df[y].tolist() if y else None _x = df['timestamp'].tolist() if x in DATE_FIELDS else df[x] if y is None: plt.scatter(_x, marker=marker, color=color, fillx=fillx) else: plt.plot(_x, y_list, marker=marker, color=color, fillx=fillx) plt.xticks(_x, x_list) if title is not None: plt.title(title) if grid: plt.grid(True, True) if background_color is not None: plt.canvas_color(background_color) plt.axes_color(background_color) if axes_color is not None: plt.ticks_color(axes_color) plt.show()
def make_figure_task_info(extractors, what): """ $ oq plot "task_info?kind=classical" """ plt = import_plt() if plt.__name__ == 'plotext': [ex] = extractors [(task_name, task_info)] = ex.get(what).to_dict().items() x = task_info['duration'] mean, std, med = x.mean(), x.std(ddof=1), numpy.median(x) plt.hist(x, bins=50) plt.title("mean=%d+-%d seconds, median=%d" % (mean, std, med)) return plt fig = plt.figure() [ex] = extractors [(task_name, task_info)] = ex.get(what).to_dict().items() x = task_info['duration'] ax = fig.add_subplot(2, 1, 1) mean, std = x.mean(), x.std(ddof=1) ax.hist(x, bins=50, rwidth=0.9) ax.set_title("mean=%d+-%d seconds" % (mean, std)) ax.set_ylabel("tasks=%d" % len(x)) from scipy.stats import linregress ax = fig.add_subplot(2, 1, 2) arr = numpy.sort(task_info, order='duration') x, y = arr['duration'], arr['weight'] reg = linregress(x, y) ax.plot(x, reg.intercept + reg.slope * x) ax.plot(x, y) ax.set_ylabel("weight") ax.set_xlabel("duration") return plt
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()
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()
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()
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("")
return len(where(output.split("\n"), "stshoot")) def generate_counts(*args): while True: yield count_lines(govc(*args)) if __name__ == '__main__': counts = 200 # number of data points interval = 0 # seconds per count xs = range(1, counts + 1) ys = [] plt.title("GOVC Session Count") plt.clc() plt.xlim(xs[0], xs[-1]) plt.xticks(ticks=[1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200]) for y in generate_counts("session.ls"): ys.append(y) while len(ys) > counts: ys.pop(0) y_min, y_max = min(ys), max(ys) + 1 plt.yticks(ticks=range(y_min, y_max)) plt.ylim(y_min, y_max) #plt.ylim(150,165) plt.cld() plt.clt()
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()
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()