当前位置: 首页>>代码示例>>Python>>正文


Python SimpleLineChart.add_marker方法代码示例

本文整理汇总了Python中pygooglechart.SimpleLineChart.add_marker方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.add_marker方法的具体用法?Python SimpleLineChart.add_marker怎么用?Python SimpleLineChart.add_marker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygooglechart.SimpleLineChart的用法示例。


在下文中一共展示了SimpleLineChart.add_marker方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createChart

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import add_marker [as 别名]

#.........这里部分代码省略.........
    # add the data
    for dd in datay.values():
        chart.add_data(dd)

    # Set the line colours
    chart.set_colours(['0000FF', 'FF0000', '00FF00', 'F0F000', '0F0F00'])

    # Set the horizontal dotted lines
    chart.set_grid(0, 25, 5, 5)
    
    # vertical stripes, the width of each stripe is calculated so that it covers one month
    ndatapoints = len(datay.values()[0])
            
    datapermonth = [ ]
    for year in xaxis:
        for month in xaxis[year]:
            datapermonth.append(xaxis[year][month])


    # mark months using range markers
    stripes = [ ]
    stripcols = ('FFFFFF', 'CCCCCC')
    wlast = 0
    for k in datapermonth:
        w = k * 1.0 / ndatapoints
        icol = len(stripes)/2 % 2
        stripes.append(stripcols[icol])
        stripes.append(w)
        wlast += w
    chart.fill_linear_stripes(Chart.CHART, 0, *stripes)

    # y axis labels
    if max_y > 30:
        left_axis = range(0, int(max_y) + 1, 5)
    elif max_y > 10:
        left_axis = range(0, int(max_y) + 1, 1)
    elif max_y > 5:
        left_axis = [ ]
        v = 0.
        while v < max_y + 0.5:
            left_axis.append(v)
            v += 0.5
    else:
        left_axis = [ ]
        v = 0.
        while v < max_y + 0.1:
            left_axis.append(v)
            v += 0.1

    left_axis[0] = '' # no label at 0
    chart.set_axis_labels(Axis.LEFT, left_axis)

    # X axis labels
    monthlabels = [ ]
    for year in xaxis:
        for imonth in xaxis[year]:
            monthlabels.append(months[imonth])

    chart.set_axis_labels(Axis.BOTTOM, monthlabels)
    chart.set_axis_labels(Axis.BOTTOM, xaxis.keys()) # years
    
    # the axis is 100 positions long, position month labels in the centre for each month
    positions = [ ]
    p = 0
    for y in xaxis:
        datax = xaxis[y]
        for k in datax:
            w = datax[k] * 100.0 / ndatapoints
            positions.append(p + w/2)
            p += w
    chart.set_axis_positions(1, positions)
    
    # position year labels at the centre of the year
    positions = [ ]
    p = 0
    for y in xaxis:
        datax = xaxis[y]
        w = sum(datax.values()) * 100.0 / ndatapoints
        positions.append(p + w/2)
        p += w
    chart.set_axis_positions(2, positions)
    
    chart.set_legend([k[0] for k in datay.keys()])
    
    # vertical stripes for marking weeks
    #weeks = [ ]
    nsundays = 0
    daycol = genColourRange(7)
    for p in range(ndatapoints):
        d = firstweekday + p
        if (d % 7) == 0:
            assertSunday(p)
            chart.add_marker(0, p, 'V', 'FF0000', 1)
        #weeks.append(daycol[d % 7])
        #weeks.append(1./ndatapoints) # this does not work if the width is less than 0.01
        #if len(weeks)/2 == 7: # from now it's repeats
        #    break
    #chart.fill_linear_stripes(Chart.CHART, 0, *weeks)
    #chart.add_marker(0, 100, 'V', 'FF0000', 1)
    return chart
开发者ID:flyeven,项目名称:scraperwiki-scraper-vault,代码行数:104,代码来源:wienerluftview.py

示例2: render

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import add_marker [as 别名]
    def render(self,data={}, context={}):

        assert self.series is not None, "'chart.series' must be set"

        converter = wfcommon.units.Converter(context["units"])

        # merge builtin defaults, context and renderer config
        config = ChartConfig()
        if context.has_key('chart'):
            config.__dict__.update(context['chart'])
        config.__dict__.update(self.__dict__)

        # create the chart
        chart = SimpleLineChart(config.width, config.height)

        colors = []
        legend_set = False
        legend = []

        chart_min = sys.maxint
        chart_max = -sys.maxint

        # Prepare series config
        ordered_series = []
        for key, serie in self.series.iteritems():
            serie_config = ChartConfig()
            serie_config.__dict__.update(config.__dict__)
            serie_config.__dict__.update(serie)
            ordered_series.append( (serie_config.order, key, serie) )

        ordered_series.sort( cmp=lambda x,y: cmp(x[0],y[0]) )

        ordered_keys = []
        for order, key, serie in ordered_series:
            ordered_keys.append(key)

        # Draws for each serie
        index=0
        for order, key, serie in ordered_series:
            serie_config = ChartConfig()
            serie_config.__dict__.update(config.__dict__)
            serie_config.__dict__.update(serie)
            serie_data = copy.copy(data[key.split('.')[0]]['series'][key.split('.')[1]])
            measure = key.split('.')[0]

            if flat(serie_data):  # Series with all data = None
                continue

            if serie_config.accumulate:
                serie_data = accumulate(serie_data)
            elif serie_config.interpolate:
                serie_data = interpolate(serie_data)

            # Compute min and max value for the serie and the whole chart
            min_data = amin(serie_data)
            chart_min = rmin(chart_min, min_data)
            if serie_data.__contains__(min_data):
                min_index = serie_data.index(min_data)
            else:
                min_index = None
            max_data = max(serie_data)
            chart_max = max(chart_max, max_data)
            if serie_data.__contains__(max_data):
                max_index = serie_data.index(max_data)
            else:
                max_index = None

            (serie_data, min_index, max_index) = compress_to(serie_data, config.nval, min_index, max_index)

            chart.add_data(serie_data)
            colors.append(_valid_color(serie_config.color))

            if serie_config.max and not max_index == None :
                max_config = ChartConfig()
                max_config.__dict__.update(serie_config.__dict__)
                max_config.__dict__.update(serie_config.max)
                str_max_data = str(round(converter.convert(measure, max_data), 1))
                chart.add_marker(index, max_index, 't'+str_max_data, _valid_color(max_config.text), max_config.size)
                chart.add_marker(index, max_index, max_config.style, _valid_color(max_config.color), max_config.thickness)

            if serie_config.min and not min_index == None:
                min_config = ChartConfig()
                min_config.__dict__.update(serie_config.__dict__)
                min_config.__dict__.update(serie_config.min)
                str_min_data = str(round(converter.convert(measure, min_data), 1))
                chart.add_marker(index, min_index, 't'+str_min_data, _valid_color(min_config.text), min_config.size)
                chart.add_marker(index, min_index, min_config.style, _valid_color(min_config.color), min_config.thickness)

            if serie_config.last:
                last_config = ChartConfig()
                last_config.__dict__.update(serie_config.__dict__)
                last_config.__dict__.update(serie_config.last)
                last_index=len(serie_data)-1
                last_data = serie_data[last_index]
                if last_data:
                    str_last_data = str(round(converter.convert(measure, last_data), 1))
                    chart.add_marker(index, last_index, 't'+str(last_data), _valid_color(last_config.text), last_config.size)
                    chart.add_marker(index, last_index, last_config.style, _valid_color(last_config.color), last_config.thickness)

            if serie_config.area:
#.........这里部分代码省略.........
开发者ID:gmassei,项目名称:wfrog,代码行数:103,代码来源:chart.py


注:本文中的pygooglechart.SimpleLineChart.add_marker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。