We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display modal composition of trips using Euler Diagrams
from itertools import combinations def get_activity_combination_number(df, activities, activity_combination): activity_str_filter = [f"{a} > 0" if a in activity_combination else f"{a} == 0" for a in activities] activity_str_filter = " & ".join(activity_str_filter) number = len(df.query(activity_str_filter)) return number subset_sizes = {} for act_pair in activity_combinations_pairs: dict_update = create_eulerd_dict(act_pair,df_wide) subset_sizes.update(dict_update) def get_activity_tuple(activities, selected_activities): return tuple(1 if activity in selected_activities else 0 for activity in activities) def get_activity_values(act1, act2, df): total_act1 = df[act1].sum() total_act2 = df[act2].sum() act1_and_act2 = df.loc[(df[act1] > 0) & (df[act2] > 0),[act1,act2]].sum().sum() return total_act1, total_act2, act1_and_act2 def get_activity_cell_counts(act1, act2, df): total_act1 = (df[act1]>0).sum() total_act2 = (df[act2]>0).sum() act1_and_act2 = len(df.loc[(df[act1] > 0) & (df[act2] > 0)]) return total_act1, total_act2, act1_and_act2 def get_activity_combination_number(df, activities, activity_combination): activity_str_filter = [f"{a} > 0" if a in activity_combination else f"{a} == 0" for a in activities] activity_str_filter = " & ".join(activity_str_filter) number = len(df.query(activity_str_filter)) return number def create_eulerd_dict(acts,df): act1, act2 = acts #total_act1, total_act2, act1_and_act2 = get_activity_values(act1, act2, df) total_act1, total_act2, act1_and_act2 = get_activity_cell_counts(act1, act2, df) d ={ get_activity_tuple(activities, acts) : int(act1_and_act2), get_activity_tuple(activities, [acts[0]]) : int(total_act1), get_activity_tuple(activities, [acts[1]]) : int(total_act2) } return d activities = [ 'train', 'subway', 'bus' ] subset_labels={get_activity_tuple(activities, [act]):act for act in activities} subset_labels.update({get_activity_tuple(activities, acts): ' - '.join(acts) for acts in activity_combinations_pairs}) list_of_tuples = [item for sublist in [list(combinations(activities, i)) for i in range(1, len(activities) + 1)] for item in sublist] subset_sizes = {get_activity_tuple(activities, combo):get_activity_combination_number(df_wide, activities, combo) for combo in list_of_tuples} fig, axes = plt.subplots(figsize=(8, 6)) diag2 = EulerDiagram( subset_sizes = subset_sizes, #subset_labels=subset_labels, set_labels = ['Train',Subway','Bus'], ax=axes) diag2
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Display modal composition of trips using Euler Diagrams
The text was updated successfully, but these errors were encountered: