1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
2# Copyright (C) 2016-2019 German Aerospace Center (DLR) and others.
3# SUMOPy module
4# Copyright (C) 2012-2017 University of Bologna - DICAM
5# This program and the accompanying materials
6# are made available under the terms of the Eclipse Public License v2.0
7# which accompanies this distribution, and is available at
8# http://www.eclipse.org/legal/epl-v20.html
9# SPDX-License-Identifier: EPL-2.0
10
11# @file    results_mpl-01-mono.py
12# @author  Joerg Schweizer
13# @date
14# @version $Id$
15
16import os
17import numpy as np
18from collections import OrderedDict
19#import  matplotlib as mpl
20from agilepy.lib_base.geometry import *
21from coremodules.misc.matplottools import *
22import agilepy.lib_base.classman as cm
23import agilepy.lib_base.arrayman as am
24from agilepy.lib_base.geometry import *
25from agilepy.lib_base.processes import Process
26
27try:
28    from scipy import interpolate
29    is_scipy = True
30except:
31    is_scipy = False
32
33
34def is_sublist(l, s):
35    sub_set = False
36    if s == []:
37        sub_set = True
38    elif s == l:
39        sub_set = True
40    elif len(s) > len(l):
41        sub_set = False
42
43    else:
44        for i in range(len(l)):
45            if l[i] == s[0]:
46                n = 1
47                while (n < len(s)) and (l[i+n] == s[n]):
48                    n += 1
49
50                if n == len(s):
51                    sub_set = True
52
53    return sub_set
54
55
56from numpy.linalg import inv
57
58
59def kf_update(X, P, Y, H, R):
60    IM = dot(H, X)
61    IS = R + dot(H, dot(P, H.T))
62    K = dot(P, dot(H.T, inv(IS)))
63    X = X + dot(K, (Y-IM))
64    P = P - dot(K, dot(IS, K.T))
65    LH = gauss_pdf(Y, IM, IS)
66    return (X, P, K, IM, IS, LH)
67
68
69def gauss_pdf(X, M, S):
70    if M.shape()[1] == 1:
71        DX = X - tile(M, X.shape()[1])
72        E = 0.5 * sum(DX * (dot(inv(S), DX)), axis=0)
73        E = E + 0.5 * M.shape()[0] * log(2 * pi) + 0.5 * log(det(S))
74        P = exp(-E)
75    elif X.shape()[1] == 1:
76        DX = tile(X, M.shape()[1]) - M
77        E = 0.5 * sum(DX * (dot(inv(S), DX)), axis=0)
78        E = E + 0.5 * M.shape()[0] * log(2 * pi) + 0.5 * log(det(S))
79        P = exp(-E)
80    else:
81        DX = X-M
82        E = 0.5 * dot(DX.T, dot(inv(S), DX))
83        E = E + 0.5 * M.shape()[0] * log(2 * pi) + 0.5 * log(det(S))
84        P = exp(-E)
85    return (P[0], E[0])
86
87
88class SpeedprofilePlotter(PlotoptionsMixin, Process):
89    def __init__(self, results, name='Speedprofile plotter with Matplotlib',
90                 info="Plots the speed profile of a selected GPS trip using matplotlib",
91                 logger=None, **kwargs):
92
93        self._init_common('speedprofileplotter', parent=results, name=name,
94                          info=info, logger=logger)
95
96        # print 'Resultplotter.__init__',results,self.parent
97        attrsman = self.get_attrsman()
98
99        self.id_trip = attrsman.add(cm.AttrConf('id_trip', kwargs.get('id_trip', -1),
100                                                groupnames=['options'],
101                                                name='Trip ID',
102                                                info='ID of GPS trip to be plotted.',
103                                                ))
104
105        self.color_line = attrsman.add(cm.AttrConf('color_line', kwargs.get('color_line', np.array([1.0, 0.4, 0.0, 0.6], np.float32)),
106                                                   groupnames=['options'],
107                                                   perm='wr',
108                                                   metatype='color',
109                                                   name='Line color',
110                                                   info='Color of plotted line in diagram.',
111                                                   ))
112
113        self.width_line = attrsman.add(cm.AttrConf('width_line', kwargs.get('width_line', 3.0),
114                                                   groupnames=['options'],
115                                                   name='Line width',
116                                                   info='Line width of plot.',
117                                                   ))
118
119        self.is_grid = attrsman.add(cm.AttrConf('is_grid', kwargs.get('is_grid', True),
120                                                groupnames=['options'],
121                                                name='Show grid?',
122                                                info='If True, shows a grid on the graphical representation.',
123                                                ))
124
125        self.titletext = attrsman.add(cm.AttrConf('titletext', kwargs.get('titletext', ''),
126                                                  groupnames=['options'],
127                                                  name='Title text',
128                                                  info='Title text. Empty text means no title.',
129                                                  ))
130
131        self.size_titlefont = attrsman.add(cm.AttrConf('size_titlefont', kwargs.get('size_titlefont', 32),
132                                                       groupnames=['options'],
133                                                       name='Title fontsize',
134                                                       info='Title fontsize.',
135                                                       ))
136
137        self.size_labelfont = attrsman.add(cm.AttrConf('size_labelfont', kwargs.get('size_labelfont', 24),
138                                                       groupnames=['options'],
139                                                       name='Label fontsize',
140                                                       info='Label fontsize.',
141                                                       ))
142        self.add_save_options()
143
144    def plot_trip(self, ax, id_trip, offsets):
145        print 'plot_trip', id_trip, type(id_trip), self.parent.parent
146
147        mapmatching = self.parent.parent
148        trips = mapmatching.trips
149
150        routeresults = self.get_routeresults()
151
152        id_route = trips.ids_route_matched[id_trip]
153        id_routeres = routeresults.ids_route.get_id_from_index(id_route)
154
155        # tripresults.pointsposition[id_routeres],\
156        # tripresults.pointsspeed[id_routeres],
157        # tripresults.pointstime[id_routeres],
158        # ids_pointedges,
159        print '  offsets', len(offsets), offsets
160        print '  speeds', len(offsets), routeresults.pointsspeeds[id_routeres]
161        # self.init_figures()
162        #fig = self.create_figure()
163        #ax = fig.add_subplot(111)
164
165        x = offsets+routeresults.pointspositions[id_routeres]
166        y = routeresults.pointsspeeds[id_routeres]
167        #ax = init_plot()
168        print '  offsets', offsets
169        print '  position', routeresults.pointspositions[id_routeres]
170        print '  x', x
171        print '  y', y
172        #ax.plot(locations, speeds, color = self.color_line[:2], lw = self.width_line ,alpha=0.9 ,zorder = 0)
173
174        if is_scipy:
175            #x = np.arange(0, 2*np.pi+np.pi/4, 2*np.pi/8)
176            #y = np.sin(x)
177            #ax.plot(x, y, 'bo-', lw = self.width_line ,alpha=0.9 )
178            if 0:
179
180                tck = interpolate.splrep(x, y, s=0)
181                #xnew = np.arange(np.min(x), np.max(x),(np.max(x)-np.min(x))/200 )
182                xnew = np.linspace(np.min(x), np.max(x), 200)
183                ynew = interpolate.splev(xnew, tck, der=0)
184            if 1:
185                f_inter = interpolate.interp1d(x, y, kind='slinear')
186                xnew = np.linspace(x.min(), x.max(), 200)
187                ynew = f_inter(xnew)
188
189            ax.plot(xnew, ynew, 'b-', lw=self.width_line, alpha=0.9)
190            ax.plot(x, y, 'co', alpha=0.9)
191        else:
192            ax.plot(x, y, 'bo-', lw=self.width_line, alpha=0.9)
193
194    def show(self):
195        print 'show', self.id_trip, type(self.id_trip), self.parent.parent
196        # if self.axis  is None:
197
198        if self.id_trip >= 0:
199            id_trip = self.id_trip
200            mapmatching = self.parent.parent
201            trips = mapmatching.trips
202            #points = mapmatching.points
203            routes = trips.get_routes()
204            scenario = mapmatching.get_scenario()
205            edges = scenario.net.edges
206            nodes = scenario.net.nodes
207
208            routeresults = self.get_routeresults()
209            id_route = trips.ids_route_matched[id_trip]
210            route = routes.ids_edge[id_route]
211            id_routeres = routeresults.ids_route.get_id_from_index(id_route)
212
213            ids_pointedge = routeresults.ids_pointedges[id_routeres]
214            print '  id_route,id_routeres', id_route, id_routeres
215            # print '  routeresults.ids_pointedges',routeresults.ids_pointedges.get_value()
216            # print '  routeresults.pointsspeeds',routeresults.pointsspeeds.get_value()
217            # print '  ids_pointedge',ids_pointedge
218            n_point = len(ids_pointedge)
219            offsets = np.zeros(n_point, dtype=np.float32)
220            offset = 0
221            id_edge_last = ids_pointedge[0]
222            for i, id_edge in zip(np.arange(n_point), ids_pointedge):
223                if id_edge != id_edge_last:
224                    offset += edges.lengths[ids_pointedge[i-1]]
225                    id_edge_last = id_edge
226                offsets[i] = offset
227
228            # tripresults.pointsposition[id_routeres],\
229            # tripresults.pointsspeed[id_routeres],
230            # tripresults.pointstime[id_routeres],
231            # ids_pointedges,
232            print '  offsets', len(offsets), offsets
233            print '  speeds', len(offsets), routeresults.pointsspeeds[id_routeres]
234            self.init_figures()
235            fig = self.create_figure()
236            ax = fig.add_subplot(111)
237
238            self.plot_trip(ax, id_trip, offsets)
239
240            # get_color()
241            # is_sublist
242            #id_route = trips.ids_route_matched[id_trip]
243            #route = routes.ids_edge[id_route]
244            #id_routeres = routeresults.ids_route.get_id_from_index(id_route)
245
246            ids_routeres_speed = routeresults.get_ids()
247            ids_route_speed = routeresults.ids_route[ids_routeres]
248
249            for route_speed, ids_pointedge_speed in zip(routes[ids_route_speed], routeresults.ids_pointedges[ids_routeres_speed]):
250                if is_sublist(route, route_speed) | is_sublist(route_speed, route):
251                    i = ids_pointedge_speed.index(route[0])
252                    j = ids_pointedge_speed.index(route[-1])
253
254                    while ids_pointedge_speed[j] == route[-1]:
255                        j += 1
256
257            #ax.legend(loc='best',shadow=True, fontsize=self.size_labelfont)
258            ax.grid(self.is_grid)
259
260            if self.titletext != '':
261                ax.set_title(self.titletext, fontsize=self.size_titlefont)
262            ax.set_xlabel('Location [m]', fontsize=self.size_labelfont)
263            ax.set_ylabel('Speed [km/h]', fontsize=self.size_labelfont)
264            ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
265            ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
266
267            # if self.is_save:
268            #    self.save_fig('routeana_speedprofile')
269
270            plt.show()
271            # show_plot()
272
273    def get_routeresults(self):
274        return self.parent.routesresults_matched
275
276    def get_scenario(self):
277        return self.parent.get_scenario()
278
279
280class EdgeresultPlotter(PlotoptionsMixin, Process):
281    def __init__(self, results, name='Plot edge results with Matplotlib',
282                 info="Creates plots of different edge results using matplotlib",
283                 logger=None, **kwargs):
284
285        self._init_common('routeresultplotter', parent=results, name=name,
286                          info=info, logger=logger)
287
288        # print 'Resultplotter.__init__',results,self.parent
289        attrsman = self.get_attrsman()
290
291        self.plotthemefuncs = {'average_speeds': self.plot_speeds_average,
292                               'inmove_speeds': self.plot_speeds_inmotion,
293                               'times_wait': self.plot_times_wait,
294                               'times_wait_tls': self.plot_times_wait_tls,
295                               'number_matched_routes': self.plot_numbers_tot_matched,
296                               'number_shortest': self.plot_numbers_tot_shortest,
297                               'total_deviation': self.plot_differences_dist_tot_shortest,
298                               'relative_deviation': self.plot_differences_dist_rel_shortest,
299                               'probabilities_matched_routes': self.plot_probabilities_tot_matched,
300                               'flows_est_matched_routes': self.plot_flows_est_matched_routes,
301                               }
302        self.plottheme = attrsman.add(cm.AttrConf('plottheme', kwargs.get('plottheme', 'average_speeds'),
303                                                  groupnames=['options'],
304                                                  choices=self.plotthemefuncs.keys(),
305                                                  name='Plot theme',
306                                                  info='Theme  or edge attribute to be plottet.',
307                                                  ))
308
309        self.add_plotoptions(**kwargs)
310        self.add_save_options(**kwargs)
311
312    def plot_all_themes(self):
313        for plottheme in self.plotthemefuncs.keys():
314            self.plottheme = plottheme
315            self.show()
316
317    def show(self):
318        print 'EdgeresultPlotter.show', self.plottheme
319        # if self.axis  is None:
320        #axis = init_plot()
321        self.init_figures()
322        fig = self.create_figure()
323        axis = fig.add_subplot(111)
324        self.plotthemefuncs[self.plottheme](axis)
325
326        print '  self.is_save', self.is_save
327        if not self.is_save:
328            print '  show_plot'
329            show_plot()
330        else:
331            figname = 'edgeplot_'+self.plottheme
332            # print '  savefig',figname
333
334            # self.save_fig('edgeplot_'+self.plottheme)
335
336            rootfilepath = self.get_scenario().get_rootfilepath()
337
338            fig.savefig("%s_%s.%s" % (rootfilepath, figname, self.figformat),
339                        format=self.figformat,
340                        dpi=self.resolution,
341                        # orientation='landscape',
342                        orientation='portrait',
343                        transparent=True)
344            plt.close(fig)
345
346    def get_edgeresults(self):
347        return self.parent.edgesresults  # must have attribute 'ids_edge'
348
349    def plot_differences_dist_rel_shortest(self, ax):
350        edgesresults = self.get_edgeresults()
351        ids_result = edgesresults.select_ids(edgesresults.numbers_tot_shortest.get_value() > 0)
352        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
353
354        self.plot_results_on_map(ax, ids_result,
355                                 edgesresults.differences_dist_tot_shortest[ids_result] /
356                                 edgesresults.numbers_tot_shortest[ids_result],
357                                 title='Deviation generated per user',
358                                 valuelabel='Generated deviation per trip [m]',
359                                 )
360
361    def plot_differences_dist_tot_shortest(self, ax):
362        edgesresults = self.get_edgeresults()
363        ids_result = edgesresults.get_ids()
364        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
365        deviation_tot = edgesresults.differences_dist_tot_shortest
366        self.plot_results_on_map(ax, ids_result,
367                                 deviation_tot[ids_result]/1000,
368                                 title='Total deviation generated per edge',
369                                 valuelabel='Generated total deviation [km]',
370                                 )
371
372    def plot_numbers_tot_shortest(self, ax):
373        edgesresults = self.get_edgeresults()
374        ids_result = edgesresults.get_ids()
375        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
376        numbers_tot_shortest = edgesresults.numbers_tot_shortest
377        self.plot_results_on_map(ax, ids_result,
378                                 numbers_tot_shortest[ids_result],
379                                 title='Edge usage from shortest routes',
380                                 valuelabel='Usage in number of persons',
381                                 )
382
383    def plot_numbers_tot_matched(self, ax):
384        edgesresults = self.get_edgeresults()
385        ids_result = edgesresults.get_ids()
386        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
387        numbers_tot_matched = edgesresults.numbers_tot_matched
388        self.plot_results_on_map(ax, ids_result,
389                                 numbers_tot_matched[ids_result],
390                                 title='Edge usage from matched routes',
391                                 valuelabel='Usage in number of persons',
392                                 )
393
394    def plot_speeds_average(self, ax):
395        edgesresults = self.parent.edgesresults
396
397        print 'plot_speeds_average'
398
399        #ids_result = edgesresults.get_ids()
400        ids_result = edgesresults.select_ids(edgesresults.numbers_tot_matched.get_value() > 0)
401
402        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
403        speeds_average = self.parent.edgesresults.speeds_average
404        print '  speeds_average', speeds_average[ids_result]
405        print '  ids_result', ids_result
406
407        self.plot_results_on_map(ax, ids_result,
408                                 speeds_average[ids_result]*3.6,
409                                 title='Average edge speeds',
410                                 valuelabel='Average edge speeds [km/h]',
411                                 )
412
413    def plot_speeds_inmotion(self, ax):
414        edgesresults = self.parent.edgesresults
415        #ids_result = edgesresults.get_ids()
416        ids_result = edgesresults.select_ids(edgesresults.numbers_tot_matched.get_value() > 0)
417
418        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
419        speeds = self.parent.edgesresults.speeds_inmotion
420
421        print '  speeds_average', speeds[ids_result]
422        print '  ids_result', ids_result
423
424        self.plot_results_on_map(ax, ids_result,
425                                 speeds[ids_result]*3.6,
426                                 title='Average edge speeds in motion',
427                                 valuelabel='Average edge speeds in motion [km/h]',
428                                 )
429
430    def plot_times_wait(self, ax):
431        edgesresults = self.parent.edgesresults
432        #ids_result = edgesresults.get_ids()
433        ids_result = edgesresults.select_ids(edgesresults.numbers_tot_matched.get_value() > 0)
434
435        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
436        times = edgesresults.times_wait
437        self.plot_results_on_map(ax, ids_result,
438                                 times[ids_result],
439                                 title='Average wait times',
440                                 valuelabel='Average wait times [s]',
441                                 )
442
443    def plot_times_wait_tls(self, ax):
444        #ids_result = self.parent.edgesresults.get_ids()
445        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
446        edgesresults = self.parent.edgesresults
447        ids_result = edgesresults.select_ids(edgesresults.numbers_tot_matched.get_value() > 0)
448        times = edgesresults.times_wait_tls
449        self.plot_results_on_map(ax, ids_result,
450                                 times[ids_result],
451                                 title='Average wait times at Traffic Lights',
452                                 valuelabel='Average wait times at TLS [s]',
453                                 )
454
455    def plot_probabilities_tot_matched(self, ax):
456        ids_result = self.parent.edgesresults.get_ids()
457        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
458        self.plot_results_on_map(ax, ids_result,
459                                 self.parent.edgesresults.probabilities_tot_matched[ids_result],
460                                 title='Probabilities',
461                                 valuelabel=r'Enter probabilities [\%]',
462                                 )
463
464    def plot_flows_est_matched_routes(self, ax):
465        ids_result = self.parent.edgesresults.get_ids()
466        #resultattrconf = getattr(self.parent.edgesresults, self.edgeattrname)
467        self.plot_results_on_map(ax, ids_result,
468                                 self.parent.edgesresults.flows_est[ids_result],
469                                 title='Flows',
470                                 valuelabel=r'Estimated flows [1/h]',
471                                 )
472
473    def do(self):
474        # print 'do',self.edgeattrname
475        self.show()
476        return True
477
478
479class RouteresultPlotter(PlotoptionsMixin, Process):
480    def __init__(self, results, name='Plot route results with Matplotlib',
481                 info="Creates plots of different route results using matplotlib",
482                 logger=None, **kwargs):
483
484        self._init_common('routeresultplotter', parent=results, name=name,
485                          info=info, logger=logger)
486
487        print 'Resultplotter.__init__', results, self.parent
488        attrsman = self.get_attrsman()
489
490        # comprison matched shortest
491        self.is_plot_lengthdistrib = attrsman.add(cm.AttrConf('is_plot_lengthdistrib', kwargs.get('is_plot_lengthdistrib', True),
492                                                              groupnames=['options'],
493                                                              name='Plot length distribution',
494                                                              info='Plot cumulative distribution on length of matched route and shortest route.',
495                                                              ))
496
497        self.is_plot_lengthprob = attrsman.add(cm.AttrConf('is_plot_lengthprob', kwargs.get('is_plot_lengthprob', True),
498                                                           groupnames=['options'],
499                                                           name='Plot length probabilities',
500                                                           info='Plot probabilities length of matched route and shortest route.',
501                                                           ))
502
503        self.is_plot_lengthdistrib_by_class = attrsman.add(cm.AttrConf('is_plot_lengthdistrib_by_class', kwargs.get('is_plot_lengthdistrib_by_class', True),
504                                                                       groupnames=['options'],
505                                                                       name='Plot class length distribution',
506                                                                       info='Plot mean values of length of matched route and shortest route for different trip length classes.',
507                                                                       ))
508
509        self.distance_class = attrsman.add(cm.AttrConf('distance_class', kwargs.get('distance_class', 2000),
510                                                       groupnames=['options'],
511                                                       name='Class distance',
512                                                       info='Distance to generate trip length classes.',
513                                                       ))
514
515        self.is_plot_lengthratio = attrsman.add(cm.AttrConf('is_plot_lengthratio', kwargs.get('is_plot_lengthratio', True),
516                                                            groupnames=['options'],
517                                                            name='Plot length ratio',
518                                                            info='Plot  cumulative distribution  on length ratio between shortest route and matched route.',
519                                                            ))
520
521        self.is_plot_lengthoverlap = attrsman.add(cm.AttrConf('is_plot_lengthoverlap', kwargs.get('is_plot_lengthoverlap', True),
522                                                              groupnames=['options'],
523                                                              name='Plot length overlap',
524                                                              info='Plot  cumulative distribution  on overlap between shortest route and matched route.',
525                                                              ))
526
527        self.is_plot_mixshare = attrsman.add(cm.AttrConf('is_plot_mixshare', kwargs.get('is_plot_mixshare', True),
528                                                         groupnames=['options'],
529                                                         name='Plot mixed share',
530                                                         info='Plot  cumulative distribution of share of mixed access roads of shortest route and matched route.',
531                                                         ))
532
533        self.is_plot_exclusiveshare = attrsman.add(cm.AttrConf('is_plot_exclusiveshare', kwargs.get('is_plot_exclusiveshare', True),
534                                                               groupnames=['options'],
535                                                               name='Plot exclusive share',
536                                                               info='Plot  cumulative distribution of share of exclusive access roads of shortest route and matched route.',
537                                                               ))
538
539        self.is_plot_lowpriorityshare = attrsman.add(cm.AttrConf('is_plot_lowpriorityshare', kwargs.get('is_plot_lowpriorityshare', True),
540                                                                 groupnames=['options'],
541                                                                 name='Plot low priority share',
542                                                                 info='Plot  cumulative distribution of share of elow priority roads of shortest route and matched route.',
543                                                                 ))
544
545        self.is_plot_nodesdensity = attrsman.add(cm.AttrConf('is_plot_nodesdensity', kwargs.get('is_plot_nodesdensity', True),
546                                                             groupnames=['options'],
547                                                             name='Plot node ratio',
548                                                             info='Plot  cumulative distribution of node ratio between shortest route and matched route.',
549                                                             ))
550
551        self.is_plot_tldensity = attrsman.add(cm.AttrConf('is_plot_tldensity', kwargs.get('is_plot_tldensity', True),
552                                                          groupnames=['options'],
553                                                          name='Plot TL ratio',
554                                                          info='Plot  cumulative distribution of traffic light ratio between shortest route and matched route.',
555                                                          ))
556        self.is_prioritychangedensity = attrsman.add(cm.AttrConf('is_prioritychangedensity', kwargs.get('is_prioritychangedensity', True),
557                                                                 groupnames=['options'],
558                                                                 name='Plot prio. change dens.',
559                                                                 info='Plot  cumulative distribution of priority change denities between shortest route and matched route.',
560                                                                 ))
561
562        # comprison  non-overlapping matched and shortest
563        self.is_plot_lengthratio_nonoverlap = attrsman.add(cm.AttrConf('is_plot_lengthratio_nonoverlap', kwargs.get('is_plot_lengthratio_nonoverlap', True),
564                                                                       groupnames=['options'],
565                                                                       name='Plot length ratio non-overlap',
566                                                                       info='Plot cumulative distribution  on length ratio between non-overlapping parts of  shortest route and matched route.',
567                                                                       ))
568
569        self.is_plot_mixshare_nonoverlap = attrsman.add(cm.AttrConf('is_plot_mixshare_nonoverlap', kwargs.get('is_plot_mixshare_nonoverlap', True),
570                                                                    groupnames=['options'],
571                                                                    name='Plot mixed share non-overlap',
572                                                                    info='Plot  cumulative distribution of share of mixed access roads of non-overlapping parts of shortest route and matched route.',
573                                                                    ))
574
575        self.is_plot_exclusiveshare_nonoverlap = attrsman.add(cm.AttrConf('is_plot_exclusiveshare_nonoverlap', kwargs.get('is_plot_exclusiveshare_nonoverlap', True),
576                                                                          groupnames=['options'],
577                                                                          name='Plot exclusive share non-overlap',
578                                                                          info='Plot  cumulative distribution of share of exclusive access roads of non-overlapping parts of shortest route and matched route.',
579                                                                          ))
580
581        self.is_plot_lowpriorityshare_nonoverlap = attrsman.add(cm.AttrConf('is_plot_lowpriorityshare_nonoverlap', kwargs.get('is_plot_lowpriorityshare_nonoverlap', True),
582                                                                            groupnames=['options'],
583                                                                            name='Plot low priority share non-overlap',
584                                                                            info='Plot  cumulative distribution of share of low priority roads of non-overlapping parts of shortest route and matched route.',
585                                                                            ))
586
587        self.is_plot_nodesdensity_nonoverlap = attrsman.add(cm.AttrConf('is_plot_nodesdensity_nonoverlap', kwargs.get('is_plot_nodesdensity_nonoverlap', True),
588                                                                        groupnames=['options'],
589                                                                        name='Plot node ratio non-overlap',
590                                                                        info='Plot  cumulative distribution of node ratio between non-overlapping parts of shortest route and matched route.',
591                                                                        ))
592
593        self.is_plot_tldensity_nonoverlap = attrsman.add(cm.AttrConf('is_plot_tldensity_nonoverlap', kwargs.get('is_plot_tldensity_nonoverlap', True),
594                                                                     groupnames=['options'],
595                                                                     name='Plot TL ratio non-overlap',
596                                                                     info='Plot  cumulative distribution of traffic light ratio between non-overlapping parts of shortest route and matched route.',
597                                                                     ))
598
599        self.is_prioritychangedensity_nonoverlap = attrsman.add(cm.AttrConf('is_prioritychangedensity_nonoverlap', kwargs.get('is_prioritychangedensity_nonoverlap', True),
600                                                                            groupnames=['options'],
601                                                                            name='Plot prio. change dens. non-overlap',
602                                                                            info='Plot  cumulative distribution of priority change denities between non-overlapping parts of shortest route and matched route.',
603                                                                            ))
604
605        # other
606        self.n_bins = attrsman.add(cm.AttrConf('n_bins', kwargs.get('n_bins', 10),
607                                               groupnames=['options'],
608                                               name='Bin number',
609                                               info='Number of bins for histograms.',
610                                               ))
611
612        # self.add_plotoptions(**kwargs)
613        self.is_title = attrsman.add(cm.AttrConf('is_title', kwargs.get('is_title', False),
614                                                 groupnames=['options'],
615                                                 name='Show title',
616                                                 info='Show title of diagrams.',
617                                                 ))
618
619        self.size_titlefont = attrsman.add(cm.AttrConf('size_titlefont', kwargs.get('size_titlefont', 32),
620                                                       groupnames=['options'],
621                                                       name='Title fontsize',
622                                                       info='Title fontsize.',
623                                                       ))
624
625        self.size_labelfont = attrsman.add(cm.AttrConf('size_labelfont', kwargs.get('size_labelfont', 24),
626                                                       groupnames=['options'],
627                                                       name='Label fontsize',
628                                                       info='Label fontsize.',
629                                                       ))
630
631        self.width_line = attrsman.add(cm.AttrConf('width_line', kwargs.get('width_line', 2),
632                                                   groupnames=['options'],
633                                                   perm='wr',
634                                                   name='Line width',
635                                                   info='Width of plotted lines.',
636                                                   ))
637
638        self.color_line = attrsman.add(cm.AttrConf('color_line', kwargs.get('color_line', np.array([0, 0, 0, 1], dtype=np.float32)),
639                                                   groupnames=['options'],
640                                                   perm='wr',
641                                                   metatype='color',
642                                                   name='Line color',
643                                                   info='Color of line in various diagrams.',
644                                                   ))
645
646        self.color_matched = attrsman.add(cm.AttrConf('color_matched', kwargs.get('color_matched', np.array([1.0, 0.4, 0.0, 0.6], np.float32)),
647                                                      groupnames=['options'],
648                                                      perm='wr',
649                                                      metatype='color',
650                                                      name='Color matched data',
651                                                      info='Color of matched data in various diagrams.',
652                                                      ))
653
654        self.color_shortest = attrsman.add(cm.AttrConf('color_shortest', kwargs.get('color_shortest', np.array([0.23529412, 1.0, 0.0, 0.6], np.float32)),
655                                                       groupnames=['options'],
656                                                       perm='wr',
657                                                       metatype='color',
658                                                       name='Color shortest route data',
659                                                       info='Color of shortest route data in various diagrams.',
660                                                       ))
661
662        self.printformat = attrsman.add(cm.AttrConf('printformat', kwargs.get('printformat', '%.1f'),
663                                                    choices=OrderedDict([
664                                                        ('Show no values', ''),
665                                                        ('x', '%.d'),
666                                                        ('x.x', '%.1f'),
667                                                        ('x.xx', '%.2f'),
668                                                        ('x.xxx', '%.3f'),
669                                                        ('x.xxxx', '%.4f'),
670                                                    ]),
671                                                    groupnames=['options'],
672                                                    name='Label formatting',
673                                                    info='Print formatting of value label in graphical representation.',
674                                                    ))
675
676        self.color_label = attrsman.add(cm.AttrConf('color_label', kwargs.get('color_label', np.array([0, 0, 0, 1], dtype=np.float32)),
677                                                    groupnames=['options'],
678                                                    perm='wr',
679                                                    metatype='color',
680                                                    name='Label color',
681                                                    info='Color of value label in graphical representation.',
682                                                    ))
683
684        self.is_grid = attrsman.add(cm.AttrConf('is_grid', kwargs.get('is_grid', True),
685                                                groupnames=['options'],
686                                                name='Show grid?',
687                                                info='If True, shows a grid on the graphical representation.',
688                                                ))
689        self.color_background = attrsman.add(cm.AttrConf('color_background', kwargs.get('color_background', np.array([1, 1, 1, 1], dtype=np.float32)),
690                                                         groupnames=['options'],
691                                                         perm='wr',
692                                                         metatype='color',
693                                                         name='Background color',
694                                                         info='Background color of schematic network in the background.',
695                                                         ))
696
697        self.add_save_options(**kwargs)
698
699    def show(self):
700        # print 'show',self.edgeattrname
701        # if self.axis  is None:
702        self.init_figures()
703        plt.rc('lines', linewidth=self.width_line)
704        # plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
705        #                    cycler('linestyle', ['-', '--', ':', '-.'])))
706        if self.is_plot_lengthratio:
707            self.plot_lengthratio()
708
709        if self.is_plot_lengthoverlap:
710            self.plot_lengthoverlap()
711
712        if self.is_plot_lengthdistrib:
713            self.plot_lengthdistrib()
714
715        if self.is_plot_lengthprob:
716            self.plot_lengthprob()
717
718        if self.is_plot_lengthdistrib_by_class:
719            self.plot_lengthdistrib_by_class()
720
721        # --
722        if self.is_plot_lengthdistrib:
723            self.plot_lengthdistrib()
724
725        if self.is_plot_mixshare:
726            self.plot_mixshare()
727
728        if self.is_plot_exclusiveshare:
729            self.plot_exclusiveshare()
730
731        if self.is_plot_lowpriorityshare:
732            self.plot_lowpriorityshare()
733
734        if self.is_plot_nodesdensity:
735            self.plot_nodesdensity()
736
737        if self.is_plot_tldensity:
738            self.plot_tldensity()
739
740        if self.is_prioritychangedensity:
741            self.plot_prioritychangedensity()
742
743        # non overlapping
744        if self.is_plot_lengthratio_nonoverlap:
745            self.plot_lengthratio_nonoverlap()
746
747        if self.is_plot_mixshare_nonoverlap:
748            self.plot_mixshare_nonoverlap()
749
750        if self.is_plot_exclusiveshare_nonoverlap:
751            self.plot_exclusiveshare_nonoverlap()
752
753        if self.is_plot_lowpriorityshare_nonoverlap:
754            self.plot_lowpriorityshare_nonoverlap()
755
756        if self.is_plot_nodesdensity_nonoverlap:
757            self.plot_nodesdensity_nonoverlap()
758
759        if self.is_plot_tldensity_nonoverlap:
760            self.plot_tldensity_nonoverlap()
761
762        if self.is_prioritychangedensity_nonoverlap:
763            self.plot_prioritychangedensity_nonoverlap()
764
765        if not self.is_save:
766            show_plot()
767
768    def plot_tldensity(self):
769        print 'plot_tldensity'
770        fig = self.create_figure()
771        results = self.parent
772        routesresults_shortest = results.routesresults_shortest
773        routesresults_matched = results.routesresults_matched
774        edgesresults = results.edgesresults
775
776        ax = fig.add_subplot(111)
777        ids_valid = routesresults_matched.select_ids(np.logical_and(
778            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
779
780        dists_match = routesresults_matched.distances[ids_valid]
781        dists_shortest = routesresults_shortest.distances[ids_valid]
782
783        matched = routesresults_matched.numbers_nodes_tls[ids_valid]/dists_match*1000
784        shortest = routesresults_shortest.numbers_nodes_tls[ids_valid]/dists_shortest*1000
785
786        x_min = min(np.min(matched), np.min(shortest))
787        x_max = 10.0  # max(np.max(matched),np.max(shortest))
788        bins = np.linspace(x_min, x_max, self.n_bins)
789        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
790                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
791        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
792                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
793
794        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
795        ax.grid(self.is_grid)
796        if self.is_title:
797            ax.set_title('Node densities of matched and shortest route', fontsize=self.size_titlefont)
798        ax.set_xlabel('Traffic light density [1/km]', fontsize=self.size_labelfont)
799        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
800        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
801        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
802        if self.is_save:
803            self.save_fig('routeana_tldensity')
804
805    def plot_nodesdensity(self):
806        print 'plot_nodesdensity'
807        fig = self.create_figure()
808        results = self.parent
809        routesresults_shortest = results.routesresults_shortest
810        routesresults_matched = results.routesresults_matched
811        edgesresults = results.edgesresults
812
813        ax = fig.add_subplot(111)
814        ids_valid = routesresults_matched.select_ids(np.logical_and(
815            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
816
817        dists_match = routesresults_matched.distances[ids_valid]
818        dists_shortest = routesresults_shortest.distances[ids_valid]
819
820        matched = routesresults_matched.numbers_nodes[ids_valid]/dists_match*1000
821        shortest = routesresults_shortest.numbers_nodes[ids_valid]/dists_shortest*1000
822
823        x_min = min(np.min(matched), np.min(shortest))
824        x_max = max(np.max(matched), np.max(shortest))
825        bins = np.linspace(x_min, x_max, self.n_bins)
826        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
827                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
828        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
829                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
830
831        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
832        ax.grid(self.is_grid)
833        if self.is_title:
834            ax.set_title('Node densities of matched and shortest route', fontsize=self.size_titlefont)
835        ax.set_xlabel('Node density [1/km]', fontsize=self.size_labelfont)
836        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
837        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
838        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
839        if self.is_save:
840            self.save_fig('routeana_nodesdensity')
841
842    def plot_prioritychangedensity(self):
843        print 'plot_prioritychangedensity'
844        fig = self.create_figure()
845        results = self.parent
846        routesresults_shortest = results.routesresults_shortest
847        routesresults_matched = results.routesresults_matched
848        edgesresults = results.edgesresults
849
850        ax = fig.add_subplot(111)
851        ids_valid = routesresults_matched.select_ids(np.logical_and(
852            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
853
854        dists_match = routesresults_matched.distances[ids_valid]
855        dists_shortest = routesresults_shortest.distances[ids_valid]
856
857        matched = routesresults_matched.numbers_prioritychange[ids_valid]/dists_match*1000
858        shortest = routesresults_shortest.numbers_prioritychange[ids_valid]/dists_shortest*1000
859
860        x_min = min(np.min(matched), np.min(shortest))
861        x_max = max(np.max(matched), np.max(shortest))
862        bins = np.linspace(x_min, x_max, self.n_bins)
863        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
864                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
865        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
866                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
867
868        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
869        ax.grid(self.is_grid)
870        if self.is_title:
871            ax.set_title('Priority change dens. of matched and shortest route', fontsize=self.size_titlefont)
872        ax.set_xlabel('Priority change density [1/km]', fontsize=self.size_labelfont)
873        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
874        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
875        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
876        if self.is_save:
877            self.save_fig('routeana_nodesdensity')
878
879    def plot_lowpriorityshare(self):
880        print 'plot_lowpriorityshare'
881        fig = self.create_figure()
882        results = self.parent
883        routesresults_shortest = results.routesresults_shortest
884        routesresults_matched = results.routesresults_matched
885        edgesresults = results.edgesresults
886
887        ax = fig.add_subplot(111)
888        ids_valid = routesresults_matched.select_ids(np.logical_and(
889            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
890
891        dists_match = routesresults_matched.distances[ids_valid]
892        dists_shortest = routesresults_shortest.distances[ids_valid]
893
894        matched = routesresults_matched.lengths_low_priority[ids_valid]/dists_match*100
895        shortest = routesresults_shortest.lengths_low_priority[ids_valid]/dists_shortest*100
896
897        x_min = min(np.min(matched), np.min(shortest))
898        x_max = 15.0  # max(np.max(matched),np.max(shortest))
899        bins = np.linspace(x_min, x_max, self.n_bins)
900        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
901                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
902        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
903                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
904
905        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
906        ax.grid(self.is_grid)
907        if self.is_title:
908            ax.set_title('Share of low priority roads of matched and shortest route', fontsize=self.size_titlefont)
909        ax.set_xlabel('Low priority road share [%]', fontsize=self.size_labelfont)
910        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
911        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
912        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
913        if self.is_save:
914            self.save_fig('routeana_lowpriorityshare')
915
916    def plot_exclusiveshare(self):
917        print 'plot_exclusiveshare'
918        fig = self.create_figure()
919        results = self.parent
920        routesresults_shortest = results.routesresults_shortest
921        routesresults_matched = results.routesresults_matched
922        edgesresults = results.edgesresults
923
924        ax = fig.add_subplot(111)
925        ids_valid = routesresults_matched.select_ids(np.logical_and(
926            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
927
928        dists_match = routesresults_matched.distances[ids_valid]
929        dists_shortest = routesresults_shortest.distances[ids_valid]
930
931        matched = routesresults_matched.lengths_exclusive[ids_valid]/dists_match*100
932        shortest = routesresults_shortest.lengths_exclusive[ids_valid]/dists_shortest*100
933
934        x_min = min(np.min(matched), np.min(shortest))
935        x_max = max(np.max(matched), np.max(shortest))
936        bins = np.linspace(x_min, x_max, self.n_bins)
937        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
938                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
939        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
940                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
941
942        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
943        ax.grid(self.is_grid)
944        if self.is_title:
945            ax.set_title('Share of exclusive access roads of matched and shortest route', fontsize=self.size_titlefont)
946        ax.set_xlabel('Exclusive access road share [%]', fontsize=self.size_labelfont)
947        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
948        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
949        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
950        if self.is_save:
951            self.save_fig('routeana_exclusiveshare')
952
953    def plot_mixshare(self):
954        print 'plot_mixshare'
955        fig = self.create_figure()
956        results = self.parent
957        routesresults_shortest = results.routesresults_shortest
958        routesresults_matched = results.routesresults_matched
959        edgesresults = results.edgesresults
960
961        ax = fig.add_subplot(111)
962        ids_valid = routesresults_matched.select_ids(np.logical_and(
963            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
964
965        dists_match = routesresults_matched.distances[ids_valid]
966        dists_shortest = routesresults_shortest.distances[ids_valid]
967
968        matched = routesresults_matched.lengths_mixed[ids_valid]/dists_match*100
969        shortest = routesresults_shortest.lengths_mixed[ids_valid]/dists_shortest*100
970
971        x_min = min(np.min(matched), np.min(shortest))
972        x_max = max(np.max(matched), np.max(shortest))
973        bins = np.linspace(x_min, x_max, self.n_bins)
974        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
975                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
976        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
977                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
978
979        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
980        ax.grid(self.is_grid)
981        if self.is_title:
982            ax.set_title('Share of mixed reserved access roads of matched and shortest route',
983                         fontsize=self.size_titlefont)
984        ax.set_xlabel('Mixed reserved access road share [%]', fontsize=self.size_labelfont)
985        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
986        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
987        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
988        if self.is_save:
989            self.save_fig('routeana_mixshare')
990
991    def plot_lengthdistrib_by_class(self):
992        print 'plot_lengthdistrib_by_class'
993        fig = self.create_figure()
994        results = self.parent
995        routesresults_shortest = results.routesresults_shortest
996        routesresults_matched = results.routesresults_matched
997        edgesresults = results.edgesresults
998
999        ax = fig.add_subplot(111)
1000        ids_valid = routesresults_matched.select_ids(np.logical_and(
1001            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
1002
1003        dists_match = routesresults_matched.distances[ids_valid]
1004        dists_shortest = routesresults_shortest.distances[ids_valid]
1005        x_min = min(np.min(dists_match), np.min(dists_shortest))
1006        x_max = max(np.max(dists_match), np.max(dists_shortest))
1007
1008        dists_class = np.arange(0, int(x_max), self.distance_class)
1009        dists_class_center = (dists_class+0.5*self.distance_class)[1:]
1010        n_class = len(dists_class)-1
1011        means_match = np.zeros(n_class, dtype=np.float32)
1012        stds_match = np.zeros(n_class, dtype=np.float32)
1013        means_shortest = np.zeros(n_class, dtype=np.float32)
1014        stds_shortest = np.zeros(n_class, dtype=np.float32)
1015        xticklabels = []
1016        ratiolabels = []
1017        for dist_lower, dist_upper, i in zip(dists_class[:-1], dists_class[1:], range(n_class)):
1018            xticklabels.append('%d - %d' % (float(dist_lower)/1000, float(dist_upper)/1000))
1019            inds = np.logical_and(dists_match > dist_lower, dists_match < dist_upper)
1020            means_match[i] = np.mean(dists_match[inds])
1021            stds_match[i] = np.std(dists_match[inds])
1022
1023            #inds = np.logical_and(dists_shortest>dist_lower,dists_shortest<dist_upper)
1024            means_shortest[i] = np.mean(dists_shortest[inds])
1025            stds_shortest[i] = np.std(dists_shortest[inds])
1026
1027            ratiolabel = ''
1028            if (not np.isnan(means_shortest[i])) & (not np.isnan(means_match[i])):
1029                if means_match[i] > 0:
1030                    ratiolabel = '%d%%' % (means_shortest[i]/means_match[i]*100)
1031            ratiolabels.append(ratiolabel)
1032
1033        print '  dists_class_center', dists_class_center
1034        print '  means_match', means_match
1035        print '  stds_match', stds_match
1036        print '  means_shortest', means_shortest
1037        print '  stds_shortest', stds_shortest
1038
1039        x = np.arange(n_class, dtype=np.float32)  # the x locations for the groups
1040        width = 0.35       # the width of the bars
1041
1042        #        ax.bar(ind + width, women_means, width, color='y', yerr=women_std)
1043        bars1 = ax.bar(x-width, means_match, width, color=self.color_matched, yerr=stds_match)
1044        bars2 = ax.bar(x+0*width, means_shortest, width, color=self.color_shortest, yerr=stds_shortest)
1045        #bars1 = ax.bar(dists_class_center+0.35*self.distance_class, means_match, 0.25*self.distance_class, color=self.color_matched, yerr=stds_match)
1046        #bars2 = ax.bar(dists_class_center-0.35*self.distance_class, means_shortest, 0.25*self.distance_class, color=self.color_shortest, yerr=stds_shortest)
1047
1048        #ax.legend(loc='best',shadow=True, fontsize=self.size_labelfont)
1049        ax.legend((bars1[0], bars2[0]), ('matched', 'shortest'),
1050                  shadow=True, fontsize=self.size_labelfont, loc='best')
1051
1052        # if self.is_grid:
1053        ax.yaxis.grid(self.is_grid)
1054
1055        if self.is_title:
1056            ax.set_title('Mean length by trip length class', fontsize=self.size_titlefont)
1057        ax.set_xlabel('Length classes [km]', fontsize=self.size_labelfont)
1058        ax.set_ylabel('Mean length [m]', fontsize=self.size_labelfont)
1059
1060        ax.set_xticks(x)
1061        ax.set_xticklabels(xticklabels)
1062        # self._autolabel_bars(ax,bars1,means_match)
1063        self._autolabel_bars(ax, bars2, ratiolabels)
1064
1065        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1066        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1067        if self.is_save:
1068            self.save_fig('routeana_lengthdistrib_by_class')
1069
1070    def _autolabel_bars(self, ax, bars, labels):
1071        """
1072        Attach a text label above each bar displaying its height
1073        """
1074        for rect, label in zip(bars, labels):
1075            height = rect.get_height()
1076            if not np.isnan(height):
1077                ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
1078                        '%s' % label,
1079                        ha='center', va='bottom',
1080                        fontsize=int(0.8*self.size_labelfont),
1081                        )
1082
1083    def plot_lengthdistrib(self):
1084        print 'plot_lengthdistrib'
1085        fig = self.create_figure()
1086        results = self.parent
1087        routesresults_shortest = results.routesresults_shortest
1088        routesresults_matched = results.routesresults_matched
1089        edgesresults = results.edgesresults
1090
1091        ax = fig.add_subplot(111)
1092        ids_overlength = routesresults_matched.select_ids(np.logical_and(
1093            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 20000))
1094        print '  len(ids_overlength)', len(ids_overlength)
1095        print '  ids_overlength', ids_overlength
1096
1097        ids_valid = routesresults_matched.select_ids(np.logical_and(routesresults_shortest.distances.get_value(
1098        ) > 0, routesresults_matched.distances.get_value() > 0, routesresults_matched.distances.get_value() < 20000))
1099
1100        dists_match = routesresults_matched.distances[ids_valid]
1101        dists_shortest = routesresults_shortest.distances[ids_valid]
1102
1103        x_min = min(np.min(dists_match), np.min(dists_shortest))
1104        x_max = max(np.max(dists_match), np.max(dists_shortest))
1105        bins = np.linspace(x_min, x_max, self.n_bins)
1106        bincenters = self.plot_hist(ax, dists_match, bins=bins, color=self.color_matched,
1107                                    label='matched:'+'$\mu = %dm$, $\sigma=%dm$' % (np.mean(dists_match), np.std(dists_match)))
1108        bincenters = self.plot_hist(ax, dists_shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1109                                    '$\mu = %dm$, $\sigma=%dm$' % (np.mean(dists_shortest), np.std(dists_shortest)))
1110
1111        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1112        ax.grid(self.is_grid)
1113        if self.is_title:
1114            ax.set_title('Length distribution of matched and shortest route', fontsize=self.size_titlefont)
1115        ax.set_xlabel('Length [m]', fontsize=self.size_labelfont)
1116        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1117        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1118        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1119        if self.is_save:
1120            self.save_fig('routeana_lengthdistrib')
1121
1122    def plot_lengthprob(self):
1123        print 'plot_lengthprob'
1124        fig = self.create_figure()
1125        results = self.parent
1126        routesresults_shortest = results.routesresults_shortest
1127        routesresults_matched = results.routesresults_matched
1128        edgesresults = results.edgesresults
1129
1130        ax = fig.add_subplot(111)
1131        ids_valid = routesresults_matched.select_ids(np.logical_and(
1132            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
1133
1134        dists_match = routesresults_matched.distances[ids_valid]
1135        dists_shortest = routesresults_shortest.distances[ids_valid]
1136
1137        x_min = min(np.min(dists_match), np.min(dists_shortest))
1138        x_max = max(np.max(dists_match), np.max(dists_shortest))
1139        bins = np.linspace(x_min, x_max, self.n_bins)
1140        w_bin = bins[1]-bins[0]
1141        bincenters = self.plot_hist(ax, dists_match, bins=bins,
1142                                    color=self.color_matched,
1143                                    label='matched:' +
1144                                    '$\mu = %dm$, $\sigma=%dm$' % (np.mean(dists_match), np.std(dists_match)),
1145                                    is_rel_frequ=True,
1146                                    is_percent=True,
1147                                    )
1148        bincenters = self.plot_hist(ax, dists_shortest, bins=bins,
1149                                    color=self.color_shortest,
1150                                    label='shortest:' +
1151                                    '$\mu = %dm$, $\sigma=%dm$' % (np.mean(dists_shortest), np.std(dists_shortest)),
1152                                    is_rel_frequ=True,
1153                                    is_percent=True,
1154                                    )
1155
1156        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1157        ax.grid(self.is_grid)
1158        if self.is_title:
1159            ax.set_title('Relative frequency of matched and shortest route', fontsize=self.size_titlefont)
1160        ax.set_xlabel('Length [m]', fontsize=self.size_labelfont)
1161        ax.set_ylabel('Relative frequency [%]', fontsize=self.size_labelfont)
1162        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1163        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1164        if self.is_save:
1165            self.save_fig('routeana_lengthprob')
1166
1167    def plot_lengthoverlap(self):
1168        print 'plot_lengthoverlap'
1169        fig = self.create_figure()
1170        results = self.parent
1171        routesresults_shortest = results.routesresults_shortest
1172        routesresults_matched = results.routesresults_matched
1173        edgesresults = results.edgesresults
1174
1175        ax = fig.add_subplot(111)
1176        bins = np.linspace(0.0, 1.0, self.n_bins)
1177
1178        ids_valid = routesresults_matched.select_ids(np.logical_and(
1179            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
1180        values = routesresults_shortest.lengths_overlap_matched[ids_valid]/routesresults_matched.distances[ids_valid]
1181        bincenters = self.plot_hist(ax, values,
1182                                    bins=bins, histtype='bar',
1183                                    label=r'$\mu = %.2f$, $\sigma=%.2f$' % (np.mean(values), np.std(values))
1184                                    )
1185
1186        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1187        ax.grid(self.is_grid)
1188        if self.is_title:
1189            ax.set_title('Share of overlap between shortest path and matched path', fontsize=self.size_titlefont)
1190        ax.set_xlabel('Overlap share between shortest and matched path', fontsize=self.size_labelfont)
1191        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1192        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1193        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1194
1195        self.set_figmargins()
1196        if self.is_save:
1197            self.save_fig('routeana_lengthoverlap')
1198
1199    def plot_lengthratio(self):
1200        print 'plot_lengthratio'
1201        fig = self.create_figure()
1202        results = self.parent
1203        routesresults_shortest = results.routesresults_shortest
1204        routesresults_matched = results.routesresults_matched
1205        edgesresults = results.edgesresults
1206
1207        ax = fig.add_subplot(111)
1208        bins = np.linspace(0.0, 1.0, self.n_bins)
1209
1210        ids_valid = routesresults_matched.select_ids(np.logical_and(
1211            routesresults_shortest.distances.get_value() > 0, routesresults_matched.distances.get_value() > 0))
1212        values = routesresults_shortest.distances[ids_valid]/routesresults_matched.distances[ids_valid]
1213        bincenters = self.plot_hist(ax, values,
1214                                    bins=bins, histtype='bar',
1215                                    label=r'$\mu = %.2f$, $\sigma=%.2f$' % (np.mean(values), np.std(values))
1216                                    )
1217
1218        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1219        ax.grid(self.is_grid)
1220        if self.is_title:
1221            ax.set_title('Ratio distance shortest path over matched path', fontsize=self.size_titlefont)
1222        ax.set_xlabel('Ratio shortest path length/matched path length', fontsize=self.size_labelfont)
1223        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1224        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1225        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1226
1227        self.set_figmargins()
1228        if self.is_save:
1229            self.save_fig('routeana_lengthratio')
1230
1231
1232# -------------------------------------------------------------------------------
1233    # non-overlap
1234
1235    def plot_lengthratio_nonoverlap(self):
1236        print 'plot_lengthratio_nonoverlap'
1237        fig = self.create_figure()
1238        results = self.parent
1239        routesresults_shortest = results.routesresults_shortest
1240        routesresults_matched = results.routesresults_matched
1241        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1242        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1243
1244        edgesresults = results.edgesresults
1245
1246        ax = fig.add_subplot(111)
1247        bins = np.linspace(0.0, 1.0, self.n_bins)
1248
1249        ids_valid = routesresults_matched.select_ids(np.logical_and(
1250            routesresults_shortest_nonoverlap.distances.get_value() > 0,
1251            routesresults_matched_nonoverlap.distances.get_value() > 0)
1252        )
1253
1254        values = routesresults_shortest_nonoverlap.distances[ids_valid] / \
1255            routesresults_matched_nonoverlap.distances[ids_valid]
1256        bincenters = self.plot_hist(ax, values,
1257                                    bins=bins, histtype='bar',
1258                                    label=r'$\mu = %.2f$, $\sigma=%.2f$' % (np.mean(values), np.std(values))
1259                                    )
1260
1261        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1262        ax.grid(self.is_grid)
1263        if self.is_title:
1264            ax.set_title('Ratio distance of non-overlapping shortest over matched path', fontsize=self.size_titlefont)
1265        ax.set_xlabel('Ratio shortest n.o. path length/matched path length', fontsize=self.size_labelfont)
1266        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1267        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1268        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1269
1270        self.set_figmargins()
1271        if self.is_save:
1272            self.save_fig('routeana_lengthratio_nonoverlap')
1273
1274    def plot_tldensity_nonoverlap(self):
1275        print 'plot_tldensity_nonoverlap'
1276        fig = self.create_figure()
1277        results = self.parent
1278        routesresults_shortest = results.routesresults_shortest
1279        routesresults_matched = results.routesresults_matched
1280        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1281        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1282        edgesresults = results.edgesresults
1283
1284        ax = fig.add_subplot(111)
1285        ids_valid = routesresults_matched.select_ids(np.logical_and(
1286            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1287
1288        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1289        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1290
1291        matched = routesresults_matched_nonoverlap.numbers_nodes_tls[ids_valid]/dists_match*1000
1292        shortest = routesresults_shortest_nonoverlap.numbers_nodes_tls[ids_valid]/dists_shortest*1000
1293
1294        x_min = min(np.min(matched), np.min(shortest))
1295        x_max = 10.0  # max(np.max(matched),np.max(shortest))
1296        bins = np.linspace(x_min, x_max, self.n_bins)
1297        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1298                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
1299        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1300                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
1301
1302        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1303        ax.grid(self.is_grid)
1304        if self.is_title:
1305            ax.set_title('Node densities of non-overlapping matched and shortest route', fontsize=self.size_titlefont)
1306        ax.set_xlabel('Traffic light density  n.o. [1/km]', fontsize=self.size_labelfont)
1307        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1308        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1309        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1310        if self.is_save:
1311            self.save_fig('routeana_tldensity_nonoverlap')
1312
1313    def plot_nodesdensity_nonoverlap(self):
1314        print 'plot_nodesdensity_nonoverlap'
1315        fig = self.create_figure()
1316        results = self.parent
1317        routesresults_shortest = results.routesresults_shortest
1318        routesresults_matched = results.routesresults_matched
1319        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1320        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1321        edgesresults = results.edgesresults
1322
1323        ax = fig.add_subplot(111)
1324        ids_valid = routesresults_matched.select_ids(np.logical_and(
1325            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1326
1327        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1328        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1329
1330        matched = routesresults_matched_nonoverlap.numbers_nodes[ids_valid]/dists_match*1000
1331        shortest = routesresults_shortest_nonoverlap.numbers_nodes[ids_valid]/dists_shortest*1000
1332
1333        x_min = min(np.min(matched), np.min(shortest))
1334        x_max = max(np.max(matched), np.max(shortest))
1335        bins = np.linspace(x_min, x_max, self.n_bins)
1336        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1337                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
1338        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1339                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
1340
1341        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1342        ax.grid(self.is_grid)
1343        if self.is_title:
1344            ax.set_title('Node densities of non-overlapping matched and shortest route', fontsize=self.size_titlefont)
1345        ax.set_xlabel('Node density  n.o. [1/km]', fontsize=self.size_labelfont)
1346        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1347        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1348        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1349        if self.is_save:
1350            self.save_fig('routeana_nodesdensity_nonoverlap')
1351
1352    def plot_prioritychangedensity_nonoverlap(self):
1353        print 'plot_prioritychangedensity_nonoverlap'
1354        fig = self.create_figure()
1355        results = self.parent
1356        routesresults_shortest = results.routesresults_shortest
1357        routesresults_matched = results.routesresults_matched
1358        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1359        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1360        edgesresults = results.edgesresults
1361
1362        ax = fig.add_subplot(111)
1363        ids_valid = routesresults_matched.select_ids(np.logical_and(
1364            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1365
1366        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1367        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1368
1369        matched = routesresults_matched_nonoverlap.numbers_prioritychange[ids_valid]/dists_match*1000
1370        shortest = routesresults_shortest_nonoverlap.numbers_prioritychange[ids_valid]/dists_shortest*1000
1371
1372        x_min = min(np.min(matched), np.min(shortest))
1373        x_max = max(np.max(matched), np.max(shortest))
1374        bins = np.linspace(x_min, x_max, self.n_bins)
1375        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1376                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(matched), np.std(matched)))
1377        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1378                                    '$\mu = %.2f/km$, $\sigma=%.2f/km$' % (np.mean(shortest), np.std(shortest)))
1379
1380        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1381        ax.grid(self.is_grid)
1382        if self.is_title:
1383            ax.set_title('Priority change dens. of non-overlapping matched and shortest route',
1384                         fontsize=self.size_titlefont)
1385        ax.set_xlabel('Priority change density  n.o. [1/km]', fontsize=self.size_labelfont)
1386        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1387        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1388        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1389        if self.is_save:
1390            self.save_fig('routeana_nodesdensity_nonoverlap')
1391
1392    def plot_lowpriorityshare_nonoverlap(self):
1393        print 'plot_lowpriorityshare_nonoverlap'
1394        fig = self.create_figure()
1395        results = self.parent
1396        routesresults_shortest = results.routesresults_shortest
1397        routesresults_matched = results.routesresults_matched
1398        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1399        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1400        edgesresults = results.edgesresults
1401
1402        ax = fig.add_subplot(111)
1403        ids_valid = routesresults_matched.select_ids(np.logical_and(
1404            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1405
1406        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1407        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1408
1409        matched = routesresults_matched_nonoverlap.lengths_low_priority[ids_valid]/dists_match*100
1410        shortest = routesresults_shortest_nonoverlap.lengths_low_priority[ids_valid]/dists_shortest*100
1411
1412        x_min = min(np.min(matched), np.min(shortest))
1413        x_max = 15.0  # max(np.max(matched),np.max(shortest))
1414        bins = np.linspace(x_min, x_max, self.n_bins)
1415        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1416                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
1417        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1418                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
1419
1420        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1421        ax.grid(self.is_grid)
1422        if self.is_title:
1423            ax.set_title('Share of low priority roads of non-overlapping matched and shortest route',
1424                         fontsize=self.size_titlefont)
1425        ax.set_xlabel('Low priority road share  n.o. [%]', fontsize=self.size_labelfont)
1426        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1427        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1428        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1429        if self.is_save:
1430            self.save_fig('routeana_lowpriorityshare_nonoverlap')
1431
1432    def plot_exclusiveshare_nonoverlap(self):
1433        print 'plot_exclusiveshare_nonoverlap'
1434        fig = self.create_figure()
1435        results = self.parent
1436        routesresults_shortest = results.routesresults_shortest
1437        routesresults_matched = results.routesresults_matched
1438        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1439        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1440        edgesresults = results.edgesresults
1441
1442        ax = fig.add_subplot(111)
1443        ids_valid = routesresults_matched.select_ids(np.logical_and(
1444            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1445
1446        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1447        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1448
1449        matched = routesresults_matched_nonoverlap.lengths_exclusive[ids_valid]/dists_match*100
1450        shortest = routesresults_shortest_nonoverlap.lengths_exclusive[ids_valid]/dists_shortest*100
1451
1452        x_min = min(np.min(matched), np.min(shortest))
1453        x_max = max(np.max(matched), np.max(shortest))
1454        bins = np.linspace(x_min, x_max, self.n_bins)
1455        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1456                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
1457        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1458                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
1459
1460        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1461        ax.grid(self.is_grid)
1462        if self.is_title:
1463            ax.set_title('Share of exclusive access roads of non-overlapping matched and shortest route',
1464                         fontsize=self.size_titlefont)
1465        ax.set_xlabel('Exclusive access road share  n.o. [%]', fontsize=self.size_labelfont)
1466        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1467        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1468        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1469        if self.is_save:
1470            self.save_fig('routeana_exclusiveshare_nonoverlap')
1471
1472    def plot_mixshare_nonoverlap(self):
1473        print 'plot_mixshare_nonoverlap'
1474        fig = self.create_figure()
1475        results = self.parent
1476        routesresults_shortest = results.routesresults_shortest
1477        routesresults_matched = results.routesresults_matched
1478        routesresults_shortest_nonoverlap = results.routesresults_shortest_nonoverlap
1479        routesresults_matched_nonoverlap = results.routesresults_matched_nonoverlap
1480        edgesresults = results.edgesresults
1481
1482        ax = fig.add_subplot(111)
1483        ids_valid = routesresults_matched.select_ids(np.logical_and(
1484            routesresults_shortest_nonoverlap.distances.get_value() > 0, routesresults_matched_nonoverlap.distances.get_value() > 0))
1485
1486        dists_match = routesresults_matched_nonoverlap.distances[ids_valid]
1487        dists_shortest = routesresults_shortest_nonoverlap.distances[ids_valid]
1488
1489        matched = routesresults_matched_nonoverlap.lengths_mixed[ids_valid]/dists_match*100
1490        shortest = routesresults_shortest_nonoverlap.lengths_mixed[ids_valid]/dists_shortest*100
1491
1492        x_min = min(np.min(matched), np.min(shortest))
1493        x_max = max(np.max(matched), np.max(shortest))
1494        bins = np.linspace(x_min, x_max, self.n_bins)
1495        bincenters = self.plot_hist(ax, matched, bins=bins, color=self.color_matched, label='matched:' +
1496                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(matched), np.std(matched)))
1497        bincenters = self.plot_hist(ax, shortest, bins=bins, color=self.color_shortest, label='shortest:' +
1498                                    '$\mu = %.2f$%%, $\sigma=%.2f$%%' % (np.mean(shortest), np.std(shortest)))
1499
1500        ax.legend(loc='best', shadow=True, fontsize=self.size_labelfont)
1501        ax.grid(self.is_grid)
1502        if self.is_title:
1503            ax.set_title('Share of mixed reserved access roads of non-overlapping matched and shortest route',
1504                         fontsize=self.size_titlefont)
1505        ax.set_xlabel('Mixed reserved access road share n.o. [%]', fontsize=self.size_labelfont)
1506        ax.set_ylabel('Probability distribution', fontsize=self.size_labelfont)
1507        ax.tick_params(axis='x', labelsize=int(0.8*self.size_labelfont))
1508        ax.tick_params(axis='y', labelsize=int(0.8*self.size_labelfont))
1509        if self.is_save:
1510            self.save_fig('routeana_mixshare_nonoverlap')
1511# -------------------------------------------------------------------------------
1512
1513    def do(self):
1514        # print 'do',self.edgeattrname
1515        self.show()
1516
1517    def get_scenario(self):
1518        return self.parent.get_scenario()
1519