Beispiel #1
0
    def graph(self):
        ''' graphs the map using google graph api '''

        chart = ScatterChart(MAP_SIZE, MAP_SIZE, 
                            x_range=(0, MAP_SIZE), y_range=(0, MAP_SIZE))
        cs = copy.deepcopy(self.cities)

        xdata = [c.getx() for c in cs]
        ydata = [c.gety() for c in cs]
        chart.add_data(xdata)
        chart.add_data(ydata)
        webbrowser.open(chart.get_url())
Beispiel #2
0
def scatter_random_marker_sizes():
    chart = ScatterChart(settings.width, settings.height, 
                         x_range=(0, 100), y_range=(0, 100))
    chart.add_data(helper.random_data())
    chart.add_data(helper.random_data())
    chart.add_data(helper.random_data())
    chart.download('scatter-random-marker-sizes.png')
Beispiel #3
0
def scatter_random_marker_sizes():
    chart = ScatterChart(settings.width, settings.height, 
                         x_range=(0, 100), y_range=(0, 100))
    chart.add_data(helper.random_data())
    chart.add_data(helper.random_data())
    chart.add_data(helper.random_data())
    chart.download('scatter-random-marker-sizes.png')
Beispiel #4
0
def scatter_circle():
    chart = ScatterChart(settings.width, settings.height, 
                         x_range=(0, 100), y_range=(0, 100))
    steps = 40
    xradius = 25
    yradius = 45
    xmid = 50
    ymid = 50
    xlist = []
    ylist = []
    for angle in xrange(0, steps + 1):
        angle = float(angle) / steps * math.pi * 2
        xlist.append(math.cos(angle) * xradius + xmid)
        ylist.append(math.sin(angle) * yradius + ymid)
    chart.add_data(xlist)
    chart.add_data(ylist)
    chart.add_data(range(len(ylist)))
    chart.add_marker(0, 1.0, 'o', '00ff00', 10)
    chart.download('scatter-circle.png')
Beispiel #5
0
 def buildScatterChart(self, data, xKey, yKey, x_range=None, y_range=None, buildLabels=False):
     chart = ScatterChart(self.defaultWidth, self.defaultHeight, x_range=x_range, y_range=y_range)
     
     xData = list()
     yData = list()
     
     for item in data:
         xData.append(item[xKey])
         yData.append(item[yKey])
         
     if not x_range: x_range = (0, max(xData))
     if not y_range: y_range = (0, max(yData))
     
     chart.add_data(xData)
     chart.add_data(yData)
         
     if buildLabels:
         chart.set_axis_labels('x', self.buildLabels(x_range))
         chart.set_axis_labels('y', self.buildLabels(y_range))
     
     return chart
Beispiel #6
0
    def buildScatterChart(self,
                          data,
                          xKey,
                          yKey,
                          x_range=None,
                          y_range=None,
                          buildLabels=False):
        chart = ScatterChart(self.defaultWidth,
                             self.defaultHeight,
                             x_range=x_range,
                             y_range=y_range)

        xData = list()
        yData = list()

        for item in data:
            xData.append(item[xKey])
            yData.append(item[yKey])

        if not x_range: x_range = (0, max(xData))
        if not y_range: y_range = (0, max(yData))

        chart.add_data(xData)
        chart.add_data(yData)

        if buildLabels:
            chart.set_axis_labels('x', self.buildLabels(x_range))
            chart.set_axis_labels('y', self.buildLabels(y_range))

        return chart
Beispiel #7
0
def scatter_circle():
    chart = ScatterChart(settings.width, settings.height, 
                         x_range=(0, 100), y_range=(0, 100))
    steps = 40
    xradius = 25
    yradius = 45
    xmid = 50
    ymid = 50
    xlist = []
    ylist = []
    for angle in range(0, steps + 1):
        angle = float(angle) / steps * math.pi * 2
        xlist.append(math.cos(angle) * xradius + xmid)
        ylist.append(math.sin(angle) * yradius + ymid)
    chart.add_data(xlist)
    chart.add_data(ylist)
    chart.add_data(list(range(len(ylist))))
    chart.add_marker(0, 1.0, 'o', '00ff00', 10)
    chart.download('scatter-circle.png')
Beispiel #8
0
    def buildTagBuddiesWallPosterScatterChart(self, data):
        chart = ScatterChart(self.defaultWidth, self.defaultHeight)

        xData = list()
        yData = list()

        for item in data.values():
            xData.append(item[0])
            yData.append(item[1])

        chart.add_data(xData)
        chart.add_data(yData)

        chart.set_axis_labels('x', self.buildLabels((0, max(xData))))
        chart.set_axis_labels('y', self.buildLabels((0, max(yData))))

        chart.set_title('Wall Posts - Common Photo Tags')

        return chart
Beispiel #9
0
def scatter_bg():
   
    chart = ScatterChart(width=100, height=100 ,x_range=(0, 10), y_range=(0, 10))

    xlist = []

    data_line1 = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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split()
    xlist4 = data_line4.split()
    
    xlist = [5,0,0,0,0,0,0,0,0,0]
    ylist = [5,0,0,0,5,0,0,0,0,10]
    zlist = [30]
    #chart.add_marker(1, 4, 'o', '00ff00', 1)

    #data = helper.random_data(4, 2)
    #print "RandomData ",data

    #print "list1",map(int,xlist1)

    #chart.add_data(map(int,xlist1))
    #chart.add_data(map(int,xlist2))
    #chart.add_data(map(int,xlist3))
    #chart.add_data(map(int,xlist4))
    
    chart.add_data(map(int,xlist))
    chart.add_data(map(int,ylist))
    #chart.add_data(map(int,zlist))
    
    chart.set_title("a Title")
    
    
    chart.download('/tmp/myscatter.png')
    
    print "Bye %s"%(chart.get_url())
Beispiel #10
0
 def buildTagBuddiesWallPosterScatterChart(self, data):
     chart = ScatterChart(self.defaultWidth, self.defaultHeight)
     
     xData = list()
     yData = list()
     
     for item in data.values():
         xData.append(item[0])
         yData.append(item[1])
     
     chart.add_data(xData)
     chart.add_data(yData)
     
     chart.set_axis_labels('x', self.buildLabels((0, max(xData))))
     chart.set_axis_labels('y', self.buildLabels((0, max(yData))))
     
     chart.set_title('Wall Posts - Common Photo Tags')
     
     return chart
Beispiel #11
0
    def generate_chart(cls, data, width=950, height=300):
        """
            Gets a github style punchcard chart.
            Hat tip: http://github.com/dustin/bindir/blob/master/gitaggregates.py
        """
        no_data = not data
        try:
            from pygooglechart import ScatterChart
        except ImportError:
            raise Exception(
                """Aw shucks, someone forgot to install the google chart library
on this machine and the report needs it. To get it, run
easy_install pygooglechart.  Until you do that this won't work.
"""
            )

        chart = ScatterChart(width, height, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d = []
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes = []
        for d in days:
            sizes.extend([data["%d %02d" % (d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        if no_data:
            # fill in a line out of view so that chart.get_url() doesn't crash
            sizes.extend([1] * 24)
        chart.add_data(sizes)

        chart.set_axis_labels("x", [""] + [str(h) for h in range(24)] + [""])
        chart.set_axis_labels("y", [""] + [day_names[n] for n in days] + [""])

        chart.add_marker(1, 1.0, "o", "333333", 25)
        return chart.get_url() + "&chds=-1,24,-1,7,0,20"
Beispiel #12
0
    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d=[]
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes=[]
        for d in days:
            sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        chart.add_data(sizes)

        #Easier to manually set the x label for the 12am/12pm labels 
        chart.set_axis_labels('x', ['|12am|1|2|3|4|5|6|7|8|9|10|11|12pm|1|2|3|4|5|6|7|8|9|10|11|'])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        
        chart.download(self.options.filename)
        return chart.get_url()
Beispiel #13
0
def create_google_scatter_chart(file, x_values, y_values, z_values, x_label = 'x', y_label = 'y'):
    
    x_max = max(x_values)
    y_max = max(y_values)
    z_max = max(z_values)
    
    chart = ScatterChart(600, 300, x_range=(0, x_max), y_range=(0, y_max))
    
    chart.set_legend(['speed in mbps'])
    
    left_axis = range(0, y_max + 1, 4)
    left_axis[0] = ''
    left_axis[-1] = y_label
    chart.set_axis_labels(Axis.LEFT, left_axis)

    bottom_axis = range(0, x_max + 1, 4)
    bottom_axis[0] = ''
    bottom_axis[-1] = x_label
    chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
    
    chart.add_data(x_values)
    chart.add_data(y_values)
    chart.add_data(z_values)
    
    return chart.get_url(None)
Beispiel #14
0
    def generate_chart(cls, data, width=950, height=300):
        """
            Gets a github style punchcard chart.
            Hat tip: http://github.com/dustin/bindir/blob/master/gitaggregates.py
        """
        no_data = not data
        try:
            from pygooglechart import ScatterChart
        except ImportError:
            raise Exception("WorkerActivityTimes requires pygooglechart.")

        chart = ScatterChart(width, height, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d=[]
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        # mapping between numbers 0..6 and its day of the week label
        day_names = "Mon Tue Wed Thu Fri Sat Sun".split(" ")
        # the order, bottom-to-top, in which the days should appear
        # i.e. Sun, Sat, Fri, Thu, etc
        days = (6, 5, 4, 3, 2, 1, 0)

        sizes=[]
        for d in days:
            sizes.extend([data[(d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        if no_data:
            # fill in a line out of view so that chart.get_url() doesn't crash
            sizes.extend([1] * 24)
        chart.add_data(sizes)

        chart.set_axis_labels('x', [''] + [str(h) for h  in range(24)] + [''])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        return chart.get_url() + '&chds=-1,24,-1,7,0,20'
    def to_gchart(self):
        # local import, to allow setup.py to include this file, before
        # pygooglechart is installed
        from pygooglechart import ScatterChart

        chart = ScatterChart(self.width, self.height,
                             x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h / 7) for h in range(24 * 7)])
        chart.add_data([(h % 7) for h in range(24 * 7)])

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        if self.monday_first:
            days = (0, 6, 5, 4, 3, 2, 1)
        else:
            days = (6, 5, 4, 3, 2, 1, 0)

        sizes = []
        for h in range(24):
            sizes.extend([self.h["%d %02d" % (d, h)] for d in days])
        chart.add_data(sizes)

        if self.colors:
            colors = self.colors[:]
            colors.reverse()
            chart.set_colours_within_series(colors)

        if self.title:
            chart.set_title(self.title)
        if self.is12h:
            xlabels = ('|12am|1|2|3|4|5|6|7|8|9|10|11|'
                       '12pm|1|2|3|4|5|6|7|8|9|10|11|')
        else:
            xlabels = ('|0|1|2|3|4|5|6|7|8|9|10|11|'
                       '12|13|14|15|16|17|18|19|20|21|22|23|')
        chart.set_axis_labels('x', [xlabels])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        chart.download(self.output)
Beispiel #16
0
def saveGraph(clusters, width = 500, height = 500):
    """
    Generate graph and save it as a PNG file.
    """

#    width = 500
#    height = width
    padding = 30
    xlist = []
    ylist = []
    coords = []
    i = 0
    j = 0
    pointColours = []

    for cluster in clusters:
	for point in cluster.points:
	    dimension = point.n
	    for i in xrange(dimension):
		coords.append([])
	    break
	break
    coords.append([]) # For the z-axis/colors/point size

    # Because of the braindead way of serializing the point coordinates and
    # other data about the points, this is hairy.  We specify the colour for
    # each point individually, despite really caring about the colour of the
    # whole series

    # 28 clusters supported
    palette = [
	    "FF0000" ,"00FF00" ,"0000FF" ,"FFFF00" ,"FF00FF"
	    ,"FFFF00" ,"00FFFF" ,"FF00FF" ,"00FFFF" ,"AA0000" ,"00AA00"
	    ,"0000AA" ,"AAAA00" ,"AA00AA" ,"AAAA00" ,"00AAAA" ,"AA00AA"
	    ,"00AAAA" ,"550000" ,"005500" ,"000055" ,"555500" ,"550055"
	    ,"555500" ,"005555" ,"550055" ,"005555"
	    ,
	    "FF3333" ,"33FF33" ,"3333FF" ,"FFFF33" ,"FF33FF"
	    ,"FFFF33" ,"33FFFF" ,"FF33FF" ,"33FFFF" ,"AA3333" ,"33AA33"
	    ,"3333AA" ,"AAAA33" ,"AA33AA" ,"AAAA33" ,"33AAAA" ,"AA33AA"
	    ,"33AAAA" ,"553333" ,"335533" ,"333355" ,"555533" ,"553355"
	    ,"555533" ,"335555" ,"553355" ,"335555"
	    ,
	    "FF9999" ,"99FF99" ,"9999FF" ,"FFFF99" ,"FF99FF"
	    ,"FFFF99" ,"99FFFF" ,"FF99FF" ,"99FFFF" ,"AA9999" ,"99AA99"
	    ,"9999AA" ,"AAAA99" ,"AA99AA" ,"AAAA99" ,"99AAAA" ,"AA99AA"
	    ,"99AAAA" ,"559999" ,"995599" ,"999955" ,"555599" ,"559955"
	    ,"555599" ,"995555" ,"559955" ,"995555"
	    ]
    clusterNumber = 1
    for cluster in clusters:
	for point in cluster.points:
	    for i in xrange(point.n):
		coords[i].append(point.coords[i])
	    # Different size dots
	    #coords[2].append(clusterNumber)
	    coords[2].append(5)
	    try:
		pointColours.append(palette[clusterNumber])
	    except:
		pointColours.append("000000")
	clusterNumber += 1



    xlist = coords[0]
    ylist = coords[1]
    zlist = coords[2]

    chart = ScatterChart(width, height, 
                         x_range=(min(xlist) - padding, max(xlist) + padding),
                         y_range=(min(ylist) - padding, max(ylist) + padding))
    chart.set_axis_range('x', min(xlist) - padding, max(xlist) + padding)
    chart.set_axis_range('t', min(xlist) - padding, max(xlist) + padding)
    chart.set_axis_range('y', min(ylist) - padding, max(ylist) + padding)
    chart.set_axis_range('r', min(ylist) - padding, max(ylist) + padding)

#    # Add an invisible point to allow scalling of the other points
#    # This must come after the min/max above
#    for cluster in clusters:
#	for point in cluster.points:
#	    for i in xrange(point.n):
#		coords[i].append(point.coords[i] + 16300)
#	    # Must be bigger then the rest
#	    coords[2].append(10)
#	    # White-on-white, i.e. invisible
#	    pointColours.append("FFFFFF")
#	    break
#	break

    chart.add_data(xlist)
    chart.add_data(ylist)
    chart.add_data(zlist)
    chart.set_colours_within_series(pointColours)


    chart.download(_image_file_name)
Beispiel #17
0
def compass_url(points, width=500, height=500):
    legend = lambda p: map(lambda x: x[0], p)
    data_x = lambda p: map(lambda x: float(x[1]), p)
    data_y = lambda p: map(lambda x: float(x[2]), p)
    
    chart = ScatterChart(width, height, x_range=(-10, 10), y_range=(-10, 10))
    chart.add_data(data_x(points))
    chart.add_data(data_y(points))
    chart.set_legend(legend(points))
    chart.set_legend_position('b')
    chart.set_grid(5, 5, 5, 3)
    chart.set_colours_within_series(colors(points))
    
    axis = (chart.set_axis_labels(Axis.LEFT, ['Left']),
            chart.set_axis_labels(Axis.RIGHT, ['Right']),
            chart.set_axis_labels(Axis.TOP, ['Authoritarian']),
            chart.set_axis_labels(Axis.BOTTOM, ['Libertarian']))
    
    for a in axis:
        chart.set_axis_positions(a, [50])
        chart.set_axis_style(a, '000000', '15')

        url_bits = ['%s,%s' % (a, '-180') for a in axis]
        url = chart.get_url()
        url = url + '&chxtc=' + '|'.join(url_bits)
    return url
    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d=[]
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes=[]
        for d in days:
            sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        chart.add_data(sizes)

        #Easier to manually set the x label for the 12am/12pm labels 
        chart.set_axis_labels('x', ['|12am|1|2|3|4|5|6|7|8|9|10|11|12pm|1|2|3|4|5|6|7|8|9|10|11|'])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        
        chart.download(self.options.filename)
        return chart.get_url()
Beispiel #19
0
 def run(self, serial, tag, tagname, pagename, soup, request, response):
     width = 384
     height = 512
     buckets = self.ac.indexer.hitmap.getBuckets()
     # transpose data (we might be doing sampling at a different interval, and
     # here we want weekday:hour slots)
     self.data = {}
     for t in buckets.keys():
         slot = time.strftime("%2w%2H", time.localtime(int(t)))
         if slot in self.data.keys():
             self.data[slot] = self.data[slot] + buckets[t]
         else:
             self.data[slot] = buckets[t]
     grid = {'x': [0 for x in range(6)], 'y': [0 for y in range(23)]}
     x = []
     y = []
     z = []
     buffer = []
     for slot in self.data.keys():
         x.append(1 + int(slot[0:2]))
         y.append(24 - int(slot[2:4]))
         z.append(int(self.data[slot]))
     chart = ScatterChart(width, height, x_range=(0, 7), y_range=(0, 25))
     chart.fill_solid(Chart.BACKGROUND, 'eeeeee')
     chart.add_data(x)
     chart.add_data(y)
     chart.add_data(z)
     chart.set_axis_labels(Axis.LEFT,
                           [''] + ["%02dh" % (23 - x)
                                   for x in range(24)] + [''])
     chart.set_axis_labels(
         Axis.TOP, ['', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
     chart.add_marker(0, 1.0, 'o', '00e0e040', 50)
     buffer.append('<img alt="Google Scatter Chart" src="%s">' %
                   chart.get_url())
     tag.replaceWith(u''.join(buffer))
Beispiel #20
0
def get_punchcard_url(data, width=950, height=300):
    '''
    Gets a github style punchcard chart. 
    
    Hat tip: http://github.com/dustin/bindir/blob/master/gitaggregates.py
    '''
    if not data: return ""
    try:
        from pygooglechart import ScatterChart
    except ImportError:
        raise Exception(MISSING_DEPENDECY)

    chart = ScatterChart(width, height, x_range=(-1, 24), y_range=(-1, 7))

    chart.add_data([(h % 24) for h in range(24 * 8)])

    d=[]
    for i in range(8):
        d.extend([i] * 24)
    chart.add_data(d)

    day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
    days = (0, 6, 5, 4, 3, 2, 1)

    sizes=[]
    for d in days:
        sizes.extend([data["%d %02d" % (d, h)] for h in range(24)])
    sizes.extend([0] * 24)
    chart.add_data(sizes)

    chart.set_axis_labels('x', [''] + [str(h) for h  in range(24)] + [''])
    chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

    chart.add_marker(1, 1.0, 'o', '333333', 25)
    return chart.get_url() + '&chds=-1,24,-1,7,0,20'
Beispiel #21
0
 def run(self, serial, tag, tagname, pagename, soup, request, response):
   width = 384
   height = 512
   buckets = self.ac.indexer.hitmap.getBuckets()
   # transpose data (we might be doing sampling at a different interval, and 
   # here we want weekday:hour slots)
   self.data = {}
   for t in buckets.keys():
     slot = time.strftime("%2w%2H", time.localtime(int(t)))
     if slot in self.data.keys():
       self.data[slot] = self.data[slot] + buckets[t]
     else:
       self.data[slot] = buckets[t]
   grid = {'x':[0 for x in range(6)], 'y':[0 for y in range(23)]}
   x = []
   y = []
   z = []
   buffer = []
   for slot in self.data.keys():
     x.append(1 + int(slot[0:2]))
     y.append(24 - int(slot[2:4]))
     z.append(int(self.data[slot]))
   chart = ScatterChart(width, height, x_range=(0, 7), y_range=(0, 25))
   chart.fill_solid(Chart.BACKGROUND,'eeeeee')
   chart.add_data(x)
   chart.add_data(y)
   chart.add_data(z)
   chart.set_axis_labels(Axis.LEFT, [''] + ["%02dh" % (23 - x) for x in range(24)] + [''])
   chart.set_axis_labels(Axis.TOP, ['', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
   chart.add_marker(0, 1.0, 'o', '00e0e040', 50)
   buffer.append('<img alt="Google Scatter Chart" src="%s">' % chart.get_url())
   tag.replaceWith(u''.join(buffer))
Beispiel #22
0
    def generate_chart(cls, data, width=950, height=300):
        """
            Gets a github style punchcard chart.
            Hat tip: http://github.com/dustin/bindir/blob/master/gitaggregates.py
        """
        no_data = not data
        try:
            from pygooglechart import ScatterChart
        except ImportError:
            raise Exception("WorkerActivityTimes requires pygooglechart.")

        chart = ScatterChart(width, height, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d = []
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        # mapping between numbers 0..6 and its day of the week label
        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        # the order, bottom-to-top, in which the days should appear
        # i.e. Sun, Sat, Fri, Thu, etc
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes = []
        for d in days:
            sizes.extend([data[(d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        if no_data:
            # fill in a line out of view so that chart.get_url() doesn't crash
            sizes.extend([1] * 24)
        chart.add_data(sizes)

        chart.set_axis_labels('x', [''] + [str(h) for h in range(24)] + [''])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        return chart.get_url() + '&chds=-1,24,-1,7,0,20'
Beispiel #23
0
    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d = []
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes = []
        for d in days:
            sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        chart.add_data(sizes)

        chart.set_axis_labels('x', [''] + [str(h) for h in range(24)] + [''])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        return chart.get_url() + '&chds=-1,24,-1,7,0,20'
Beispiel #24
0
    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))

        chart.add_data([(h % 24) for h in range(24 * 8)])

        d=[]
        for i in range(8):
            d.extend([i] * 24)
        chart.add_data(d)

        day_names = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
        days = (0, 6, 5, 4, 3, 2, 1)

        sizes=[]
        for d in days:
            sizes.extend([self.h["%d %02d" % (d, h)] for h in range(24)])
        sizes.extend([0] * 24)
        chart.add_data(sizes)

        chart.set_axis_labels('x', [''] + [str(h) for h  in range(24)] + [''])
        chart.set_axis_labels('y', [''] + [day_names[n] for n in days] + [''])

        chart.add_marker(1, 1.0, 'o', '333333', 25)
        return chart.get_url() + '&chds=-1,24,-1,7,0,20'
Beispiel #25
0
def create_google_scatter_chart(file,
                                x_values,
                                y_values,
                                z_values,
                                x_label='x',
                                y_label='y'):

    x_max = max(x_values)
    y_max = max(y_values)
    z_max = max(z_values)

    chart = ScatterChart(600, 300, x_range=(0, x_max), y_range=(0, y_max))

    chart.set_legend(['speed in mbps'])

    left_axis = range(0, y_max + 1, 4)
    left_axis[0] = ''
    left_axis[-1] = y_label
    chart.set_axis_labels(Axis.LEFT, left_axis)

    bottom_axis = range(0, x_max + 1, 4)
    bottom_axis[0] = ''
    bottom_axis[-1] = x_label
    chart.set_axis_labels(Axis.BOTTOM, bottom_axis)

    chart.add_data(x_values)
    chart.add_data(y_values)
    chart.add_data(z_values)

    return chart.get_url(None)