@@ -132,21 +132,21 @@ def add_graph(self, G, plot_nodes=False, edge_color="#3388ff", edge_width=3,
132132 plot_nodes: bool, optional, default: False
133133 If true, it will show the vertices of the graph.
134134 edge_color: str, optional, default: "#3388ff"
135- Colour of graph edges
135+ Colour of graph edges.
136136 edge_width: float, optional, default: 3
137- Width of graph edges
137+ Width of graph edges.
138138 edge_opacity: float, optional, default: 1
139- Opacity of graph edges
139+ Opacity of graph edges.
140140 radius: float, optional, default: 1.7
141- Radius of graph vertices
141+ Radius of graph vertices.
142142 node_color: str, optional, default: "red"
143- Colour of graph vertices
143+ Colour of graph vertices.
144144 fill: bool, optional, default: True
145145 Whether to fill the nodes with color. Set it to false to disable filling on the nodes.
146146 fill_color: str or NoneType, default: None
147147 Fill color. Defaults to the value of the color option.
148148 fill_opacity: float, optional, default: 1
149- Fill opacity
149+ Fill opacity.
150150 """
151151 edge_attr = dict ()
152152 edge_attr ["color" ] = edge_color
@@ -156,15 +156,10 @@ def add_graph(self, G, plot_nodes=False, edge_color="#3388ff", edge_width=3,
156156 node_attr = dict ()
157157 node_attr ["color" ] = node_color
158158 node_attr ["fill" ] = fill
159-
160- if not fill_color :
161- node_attr ["fill_color" ] = fill_color
162- else :
163- node_attr ["fill_color" ] = fill_color
159+ node_attr ["fill_color" ] = fill_color
164160 node_attr ["fill_opacity" ] = fill_opacity
165161
166162 nodes , edges = utils .graph_to_gdfs (G )
167- edges = utils .graph_to_gdfs (G , nodes = False )
168163
169164 fg_graph = folium .FeatureGroup (name = 'Graph edges' , show = True )
170165 self .add_child (fg_graph )
@@ -182,28 +177,56 @@ def add_graph(self, G, plot_nodes=False, edge_color="#3388ff", edge_width=3,
182177
183178 folium .LayerControl ().add_to (self )
184179
185- def draw_candidates (self , candidates , radius ):
180+ def draw_candidates (self , candidates , radius , point_radius = 1 , point_color = "black" , point_fill = True ,
181+ point_fill_opacity = 1 , area_weight = 1 , area_color = "black" , area_fill = True , area_fill_opacity = 0.2 ,
182+ cand_radius = 1 , cand_color = "orange" , cand_fill = True , cand_fill_opacity = 1 ):
186183 """ Draw the candidate nodes of the HMM matcher
187184
188185 Parameters
189186 ----------
190187 candidates: dict
191188 Candidates' dictionary computed via ``pytrack.matching.candidate.get_candidates`` method
192189 radius: float
193- Candidate search radius
190+ Candidate search radius.
191+ point_radius: float, optional, default: 1
192+ Radius of the actual GPS points.
193+ point_color: str, optional, default: "black"
194+ Colour of actual GPS points.
195+ point_fill: bool, optional, default: True
196+ Whether to fill the actual GPS points with color. Set it to false to disable filling on the nodes.
197+ point_fill_opacity: float, optional, default: 1
198+ Fill opacity of the actual GPS points.
199+ area_weight: float, optional, default: 1
200+ Stroke width in pixels of the search area.
201+ area_color: str, optional, default: "black"
202+ Colour of search area.
203+ area_fill: bool, optional, default: True
204+ Whether to fill the search area with color. Set it to false to disable filling on the nodes.
205+ area_fill_opacity: float, optional, default: 0.2
206+ Fill opacity of the search area.
207+ cand_radius: float, optional, default: 2
208+ Radius of the candidate points.
209+ cand_color: str, optional, default: "orange"
210+ Colour of candidate points.
211+ cand_fill: bool, optional, default: True
212+ Whether to fill the candidate points with color. Set it to false to disable filling on the nodes.
213+ cand_fill_opacity: float, optional, default: 1
214+ Fill opacity of the candidate GPS points.
194215 """
195216 fg_cands = folium .FeatureGroup (name = 'Candidates' , show = True , control = True )
196217 fg_gps = folium .FeatureGroup (name = "Actual GPS points" , show = True , control = True )
218+ fg_area = folium .FeatureGroup (name = "Candidate search area" , show = True , control = True )
197219 self .add_child (fg_cands )
198220 self .add_child (fg_gps )
221+ self .add_child (fg_area )
199222
200223 for i , obs in enumerate (candidates .keys ()):
201- folium .Circle (location = candidates [obs ]["observation" ], radius = radius , weight = 1 , color = "black" , fill = True ,
202- fill_opacity = 0.2 ).add_to (fg_gps )
224+ folium .Circle (location = candidates [obs ]["observation" ], radius = radius , weight = area_weight , color = area_color ,
225+ fill = area_fill , fill_opacity = area_fill_opacity ).add_to (fg_area )
203226 popup = f'{ i } -th point \n Latitude: { candidates [obs ]["observation" ][0 ]} \n Longitude: ' \
204227 f'{ candidates [obs ]["observation" ][1 ]} '
205- folium .Circle (location = candidates [obs ]["observation" ], popup = popup , radius = 1 , color = "black" ,
206- fill = True , fill_opacity = 1 ).add_to (fg_gps )
228+ folium .Circle (location = candidates [obs ]["observation" ], popup = popup , radius = point_radius , color = point_color ,
229+ fill = point_fill , point_fill_opacity = point_fill_opacity ).add_to (fg_gps )
207230
208231 # plot candidates
209232 for cand , label , cand_type in zip (candidates [obs ]["candidates" ], candidates [obs ]["edge_osmid" ],
@@ -213,14 +236,15 @@ def draw_candidates(self, candidates, radius):
213236 folium .Circle (location = cand , popup = popup , radius = 2 , color = "yellow" , fill = True ,
214237 fill_opacity = 1 ).add_to (fg_cands )
215238 else :
216- folium .Circle (location = cand , popup = popup , radius = 1 , color = "orange" , fill = True ,
217- fill_opacity = 1 ).add_to (fg_cands )
239+ folium .Circle (location = cand , popup = popup , radius = cand_radius , color = cand_color , fill = cand_fill ,
240+ fill_opacity = cand_fill_opacity ).add_to (fg_cands )
218241
219242 del self ._children [next (k for k in self ._children .keys () if k .startswith ('layer_control' ))]
220243 self .add_child (folium .LayerControl ())
221244 self ._render_reset ()
222245
223- def draw_path (self , G , trellis , predecessor , path_name = "Matched path" ):
246+ def draw_path (self , G , trellis , predecessor , path_name = "Matched path" , path_color = "green" , path_weight = 4 ,
247+ path_opacity = 1 ):
224248 """ Draw the map-matched path
225249
226250 Parameters
@@ -231,8 +255,14 @@ def draw_path(self, G, trellis, predecessor, path_name="Matched path"):
231255 Trellis DAG graph created with ``pytrack.matching.mpmatching_utils.create_trellis`` method
232256 predecessor: dict
233257 Predecessors' dictionary computed with ``pytrack.matching.mpmatching.viterbi_search`` method
234- path_name: str
258+ path_name: str, optional, default: "Matched path"
235259 Name of the path to be drawn
260+ path_color: str, optional, default: "green"
261+ Stroke color
262+ path_weight: float, optional, default: 4
263+ Stroke width in pixels
264+ path_opacity: float, optional, default: 1
265+ Stroke opacity
236266 """
237267
238268 fg_matched = folium .FeatureGroup (name = path_name , show = True , control = True )
@@ -241,19 +271,19 @@ def draw_path(self, G, trellis, predecessor, path_name="Matched path"):
241271 path_elab = mpmatching_utils .create_path (G , trellis , predecessor )
242272
243273 edge_attr = dict ()
244- edge_attr ["color" ] = "green"
245- edge_attr ["weight" ] = 4
246- edge_attr ["opacity" ] = 1
274+ edge_attr ["color" ] = path_color
275+ edge_attr ["weight" ] = path_weight
276+ edge_attr ["opacity" ] = path_opacity
247277
248278 edge = [(lat , lng ) for lng , lat in LineString ([G .nodes [node ]["geometry" ] for node in path_elab ]).coords ]
249- folium .PolyLine (locations = edge , ** edge_attr , ).add_to (fg_matched )
279+ folium .PolyLine (locations = edge , ** edge_attr ).add_to (fg_matched )
250280
251281 del self ._children [next (k for k in self ._children .keys () if k .startswith ('layer_control' ))]
252282 self .add_child (folium .LayerControl ())
253283 self ._render_reset ()
254284
255285
256- def draw_trellis (T , figsize = None , dpi = None , node_size = 500 , font_size = 8 , ** kwargs ):
286+ def draw_trellis (T , figsize = ( 15 , 12 ), dpi = 300 , node_size = 500 , font_size = 8 , ** kwargs ):
257287 """ Draw a trellis graph
258288
259289 Parameters
@@ -304,11 +334,6 @@ def draw_trellis(T, figsize=None, dpi=None, node_size=500, font_size=8, **kwargs
304334 nx_kwargs = {k : v for k , v in kwargs .items () if k in valid_nx_kwargs }
305335 plt_kwargs = {k : v for k , v in kwargs .items () if k in valid_plt_kwargs }
306336
307- if figsize is None :
308- figsize = (15 , 12 )
309- if dpi is None :
310- dpi = 300
311-
312337 plt .figure (figsize = figsize , dpi = dpi , ** plt_kwargs )
313338
314339 pos = nx .drawing .nx_pydot .graphviz_layout (T , prog = 'dot' , root = 'start' )
0 commit comments