Beispiel #1
0
 def test_map(self):
     usMap = Map()
     usMap.plotPoints([-105.16, -117.16, -77.00], [40.02, 32.73, 38.55],
                      color=GeneralMethods.getRandomColor())
     usMap.plotPoints([-114.21, -88.10], [48.25, 17.29],
                      color=GeneralMethods.getRandomColor())
     plt.show()
Beispiel #2
0
def plot_graph_clusters_on_world_map(graph,
                                     s=0,
                                     lw=0,
                                     alpha=0.6,
                                     bkcolor='#CFCFCF',
                                     *args,
                                     **kwargs):
    no_of_clusters, tuples_of_location_and_cluster_id = clusterUsingAffinityPropagation(
        graph)
    map_from_location_to_cluster_id = dict(tuples_of_location_and_cluster_id)
    map_from_cluster_id_to_cluster_color = dict([
        (i, GeneralMethods.getRandomColor()) for i in range(no_of_clusters)
    ])
    points, colors = zip(*map(
        lambda location: (getLocationFromLid(location.replace(
            '_', ' ')), map_from_cluster_id_to_cluster_color[
                map_from_location_to_cluster_id[location]]), graph.nodes()))
    _, m = plotPointsOnWorldMap(points,
                                c=colors,
                                s=s,
                                lw=lw,
                                returnBaseMapObject=True,
                                *args,
                                **kwargs)
    for u, v, data in graph.edges(data=True):
        if map_from_location_to_cluster_id[
                u] == map_from_location_to_cluster_id[v]:
            color, u, v, w = map_from_cluster_id_to_cluster_color[
                map_from_location_to_cluster_id[u]], getLocationFromLid(
                    u.replace('_', ' ')), getLocationFromLid(
                        v.replace('_', ' ')), data['w']
            m.drawgreatcircle(u[1], u[0], v[1], v[0], color=color, alpha=alpha)
    return (no_of_clusters, tuples_of_location_and_cluster_id)
Beispiel #3
0
def plot_graph_clusters_on_world_map(graph, s=0, lw=0, alpha=0.6, bkcolor='#CFCFCF', *args, **kwargs): 
    from graphs import clusterUsingAffinityPropagation 
    no_of_clusters, tuples_of_location_and_cluster_id = clusterUsingAffinityPropagation(graph)
    map_from_location_to_cluster_id = dict(tuples_of_location_and_cluster_id)
    map_from_cluster_id_to_cluster_color = dict([(i, GeneralMethods.getRandomColor()) for i in range(no_of_clusters)])
    points, colors = zip(*map(lambda  location: (getLocationFromLid(location.replace('_', ' ')), map_from_cluster_id_to_cluster_color[map_from_location_to_cluster_id[location]]), graph.nodes()))
    _, m = plotPointsOnWorldMap(points, c=colors, s=s, lw=lw, returnBaseMapObject=True,  *args, **kwargs)
    for u, v, data in graph.edges(data=True):
        if map_from_location_to_cluster_id[u]==map_from_location_to_cluster_id[v]:
            color, u, v, w = map_from_cluster_id_to_cluster_color[map_from_location_to_cluster_id[u]], getLocationFromLid(u.replace('_', ' ')), getLocationFromLid(v.replace('_', ' ')), data['w']
            m.drawgreatcircle(u[1], u[0], v[1], v[0], color=color, alpha=alpha)
    return (no_of_clusters, tuples_of_location_and_cluster_id)
Beispiel #4
0
def plotNorm(maxYValue, mu, sigma, color=None, **kwargs):
    s = np.random.normal(mu, sigma, 1000)
    count, bins = np.histogram(s, 1000, normed=True)
    if not color:
        color = GeneralMethods.getRandomColor()
    plt.fill_between(
        bins,
        ((1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(bins - mu) ** 2 / (2 * sigma ** 2))) / 4) * maxYValue,
        linewidth=1,
        color=color,
        alpha=0.3,
    )
    plt.plot(
        bins,
        ((1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(bins - mu) ** 2 / (2 * sigma ** 2))) / 4) * maxYValue,
        linewidth=3,
        color=color,
        **kwargs
    )
Beispiel #5
0
def plotNorm(maxYValue, mu, sigma, color=None, **kwargs):
    s = np.random.normal(mu, sigma, 1000)
    count, bins = np.histogram(s, 1000, normed=True)
    if not color: color = GeneralMethods.getRandomColor()
    plt.fill_between(
        bins,
        ((1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(bins - mu)**2 /
                                                    (2 * sigma**2))) / 4) *
        maxYValue,
        linewidth=1,
        color=color,
        alpha=0.3)
    plt.plot(bins,
             ((1 /
               (sigma * np.sqrt(2 * np.pi)) * np.exp(-(bins - mu)**2 /
                                                     (2 * sigma**2))) / 4) *
             maxYValue,
             linewidth=3,
             color=color,
             **kwargs)
Beispiel #6
0
 def drawKMLsForPoints(pointsIterator, outputKMLFile, color=None):
     kml = KML()
     if not color: color = GeneralMethods.getRandomColor()
     kml.addLocationPoints(pointsIterator, color=color)
     kml.write(outputKMLFile)
Beispiel #7
0
 def addLocationPoints(self, points, color=None):
     if not color: color = GeneralMethods.getRandomColor()
     for point in (list(reversed(point)) for point in points):
         pnt = self.kml.newpoint(coords=[point])
         pnt.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png'
         pnt.iconstyle.color = 'ff' + color[1:]
Beispiel #8
0
 def test_map(self):
     usMap = Map()
     usMap.plotPoints([-105.16, -117.16, -77.00], [40.02, 32.73, 38.55], color=GeneralMethods.getRandomColor())
     usMap.plotPoints([-114.21, -88.10], [48.25, 17.29], color=GeneralMethods.getRandomColor())
     plt.show()
Beispiel #9
0
 def drawKMLsForPoints(pointsIterator, outputKMLFile, color=None):
     kml = KML()
     if not color: color = GeneralMethods.getRandomColor()
     kml.addLocationPoints(pointsIterator, color=color)
     kml.write(outputKMLFile)
Beispiel #10
0
 def addLocationPoints(self, points, color=None): 
     if not color: color=GeneralMethods.getRandomColor()
     for point in (list(reversed(point)) for point in points):
         pnt = self.kml.newpoint(coords=[point])
         pnt.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png'
         pnt.iconstyle.color = 'ff'+color[1:]