-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic_plots.py
More file actions
146 lines (104 loc) · 4.75 KB
/
static_plots.py
File metadata and controls
146 lines (104 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pickle
# read data from pickle file
data = pd.read_pickle('dataframe.pkl')
pd.set_option('display.max_columns', None)
# Create figure with 4 subplots
fig, axs = plt.subplots(2, 2, figsize = (16, 12))
fig.subplots_adjust(hspace = 0.6, wspace = 0.1)
##### Plot 1: Platform Heights #####
grouped =data.groupby(['Stop name', 'Platform number'])['Platform edge height'].first().reset_index()
height=grouped['Platform edge height']
# plot the plot 1
plot1 = plt.subplot(2,2,1)
#heights =data['Platform edge height']
plot1.hist(height, color='lightgreen', ec='darkgreen', bins=10)
plot1.set_xlabel('platform edge height [cm]')
plot1.set_ylabel('frequency')
plot1.set_title('Distribution of Platform Edge Heights', size=18)
##### Plot 2: Material Overview #####
# Group by 'Stop name' and 'Platform number'
data = data[data != 'Not Applicable']
grouped_data = data.groupby(['Stop name', 'Platform number'])['Edge type'].unique().reset_index()
# Flatten the list of unique edge types
flattened_edge_types = [edge_type for sublist in grouped_data['Edge type'] for edge_type in sublist]
# Calculate the occurrences of each edge type
edge_type_counts = pd.Series(flattened_edge_types).value_counts()
print(f"Here are the absolute numbers of each group: {edge_type_counts}")
# Calculate percentages
total=edge_type_counts.sum()
percentages = [(count / total) * 100 for count in edge_type_counts]
# Create labels with percentages
labels = [f'{edge_type}: {percentage:.1f}%' for edge_type, percentage in zip(edge_type_counts.index, percentages)]
# Rearrange the order of edge types and corresponding labels
edge_type_counts = edge_type_counts.iloc[[0, 2, 1, 3]] # Change the order as desired
labels = [labels[i] for i in [0, 2, 1, 3]] # Change the order of labels accordingly
# plot the plot 2
plot2 = plt.subplot(2,2,2)
plot2.pie(edge_type_counts,
labels= labels,#edge_type_counts.index,
colors=['lightseagreen', 'skyblue', 'mediumaquamarine', 'cyan', 'seagreen'],
startangle=90,
textprops={'fontsize': 8}
)
plot2.set_title("Edge Types", size=18)
##### PLOT 3 #####
#making categories for bars
min=data['Length platform total'].min()
med=data['Length platform total'].median()
max=data['Length platform total'].max()
min_station=(data[data['Length platform total'] == 19.67])
print("The Station with the minimal platform length is:")
print(min_station)
len_data=[min, med, max]
print("Here you see the minimal, median and the maximal platform length:")
print(len_data) #[19.67, 342.69, 1206.78]
lmax=data[data['Length platform total']==1206.78]
# Get unique values for 'Stop name', 'Length platform total', and 'Platform number'
stop_name = lmax['Stop name'].unique()[0]
length_platform_total = lmax['Length platform total'].unique()[0]
platform_number = lmax['Platform number'].unique()[0]
print("The maximal platform length is located in:")
label_max=print(f"{stop_name} with {length_platform_total}m on edge {platform_number}")
# category names
x=('minimum', 'median', 'maximum')
# plot the plot 3
plot3 = plt.subplot(2,2,3)
#creating horizontal plot
plot3.barh(x, len_data) #add , label= ???
#setting title
plot3.set_title("Platform Lenghts", size=18)
#naming axes
plot3.set_xlabel("platform length [m]")
plot3.set_ylabel("")
##### Plot 4: Platform Types #####
# Filter out 'Not Applicable' values
data = data[data['Platform type'] != 'Not Applicable']
grouped_data = data.groupby(['Stop name', 'Platform number'])['Platform type'].unique().reset_index()
# Flatten the list of unique platform types
flattened_platform_types = [platform_type for sublist in grouped_data['Platform type'] for platform_type in sublist]
# Calculate the occurrences of each platform type
platform_type_counts = pd.Series(flattened_platform_types).value_counts()
print(f"Here are the absolute numbers of each group: {platform_type_counts}")
# Calculate percentages
total = platform_type_counts.sum()
percentages = [(count / total) * 100 for count in platform_type_counts]
# Rearrange the order of edge types and corresponding labels
platform_type_counts = platform_type_counts.iloc[[0, 2, 1, 3]] # Change the order as desired
labels = [labels[i] for i in [0, 2, 1, 3]] # Change the order of labels accordingly
# Create labels with percentages
labels = [f'{platform_type}: {percentage:.1f}%' for platform_type, percentage in zip(platform_type_counts.index, percentages)]
# plot the plot 4
plot4 = plt.subplot(2,2,4)
plot4.pie(platform_type_counts,
labels=labels,
colors=['lightseagreen', 'skyblue', 'mediumaquamarine', 'cyan', 'seagreen'],
startangle=90,
textprops={'fontsize': 8}
)
plot4.set_title("Platform Types", size=18)
##### Print the figure #####
plt.show()