in src/graphing/plotting.py [0:0]
def plot_percentile_intervals(
gc_event_dataframes,
group_by=None,
filter_by=None,
labels=None,
colors=None,
plot=None,
column="Duration_milliseconds",
interval_duration = 0,
percentiles = [99.99, 90, 50],
column_timing = None,
line_graph = False,
different_colors = None
):
if not interval_duration:
print("No interval length provided. Abort.")
return
# Filter and group, collecting colors and labels
timestamp_groups, datapoint_groups, labels, colors, _ = filter_and_group(gc_event_dataframes,
group_by,
filter_by,
labels,
column,
colors,
column_timing)
if not line_graph and different_colors == None:
different_colors = True
if different_colors:
from filter_and_group import get_colors_and_alphas
colors, _ = get_colors_and_alphas(len(colors) * len(percentiles))
# # if no plot is passed in, create a new plot
if not plot:
f, plot = plt.subplots()
number_of_buckets, min_time_duration, _ = get_buckets_and_range(timestamp_groups, interval_duration)
# Determine the spacing along the X axis for the data
x_alignment = [idx * interval_duration + min_time_duration for idx in range(number_of_buckets)]
if len(timestamp_groups) > len(labels):
print("Not enough labels to plot")
if len(datapoint_groups) > len(colors):
print("Not enough colors to plot")
# For each group, determine the percentile, and plot an independent line for that percentile
for group, (timestamps, dataset) in enumerate(zip(timestamp_groups, datapoint_groups)):
# First, group into buckets based on time interverals.
buckets = group_into_buckets([time - min_time_duration for time in timestamps], dataset, number_of_buckets, interval_duration)
buckets_of_percentiles = map_get_percentiles(buckets, percentiles)
# Collect the percentiles for the i-th group, percentile 0.
single_line = [buckets_of_percentiles[i][0] for i in range(len(buckets_of_percentiles))]
# Plot the first line based on the first percentile, with a label
if line_graph:
plot.plot(x_alignment, single_line, label = labels[group], color = colors[group]) # changed
else:
plot.scatter(x_alignment, single_line, label = labels[group], color = colors[group]) # changed
# Plot the rest of the percentiles, with decreasing alpha (opacity) values per line
for idx in range(1, len(percentiles)):
if different_colors:
single_line = [buckets_of_percentiles[i][idx] for i in range(len(buckets_of_percentiles))]
if line_graph:
plot.plot(x_alignment, single_line, color = colors [group + idx], alpha = 1 - 0.15 * idx )
else:
plot.scatter(x_alignment, single_line, color = colors [group + idx ], alpha = 1 - 0.15 * idx )
else:
single_line = [buckets_of_percentiles[i][idx] for i in range(len(buckets_of_percentiles))]
if line_graph:
plot.plot(x_alignment, single_line, color = colors [group], alpha = 1 - 0.15 * idx )
else:
plot.scatter(x_alignment, single_line, color = colors [group], alpha = 1 - 0.15 * idx )
# Add styling to the plot. Add legend, and x axis correct titles
plot.legend(bbox_to_anchor=(1.05, 1), loc="upper left")
return plot