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


Python SimpleLineChart.y_range方法代码示例

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


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

示例1: read

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import y_range [as 别名]
    def read(self, request, *args, **kwargs):
        self.request = request
        if kwargs.get('chart_type') == 'timeline':
            handler = PhraseOverTimeHandler()
            if request.GET.get('split_by_party') == 'true':
                resultsets = {}
                for party in ['R', 'D', ]:
                    kwargs['party'] = party
                    resultsets[party] = handler.read(request, *args, **kwargs)
                return {'results': {'url': self._partyline(resultsets), }, }

            elif request.GET.get('compare') == 'true':
                phrases = request.GET.get('phrases', '').split(',')[:5]  # Max of 5 phrases
                parties = request.GET.get('parties', '').split(',')
                states = request.GET.get('states', '').split(',')
                #chambers = request.GET.get('chambers', '').split(',')

                colors = ['8E2844', 'A85B08', 'AF9703', ]

                metadata = []
                legend_items = []
                months = None

                key = 'count'
                if self.request.GET.get('percentages') == 'true':
                    key = 'percentage'

                granularity = self.request.GET.get('granularity')

                width = int(request.GET.get('width', 575))
                height = int(request.GET.get('height', 300))
                chart = SimpleLineChart(width, height)
                chart.set_grid(0, 50, 2, 5)  # Set gridlines
                chart.fill_solid('bg', '00000000')  # Make the background transparent
                chart.set_colours(colors)
                maxcount = 0

                # Use phrases as a baseline; that is, assume that
                # there's a corresponding value for the other filters.
                # If a filter doesn't have as many values as the number
                # of phrases, the corresponding phrase will not be
                # filtered.
                # (However, if a value is set for 'party' or 'state'
                # in the querystring, that will override any values
                # set in 'phrases' or 'parties.')
                for n, phrase in enumerate(phrases):
                    chart.set_line_style(n, thickness=2)  # Set line thickness

                    if not phrase.strip():
                        continue
                    kwargs['phrase'] = phrase
                    legend = phrase
                    try:
                        kwargs['party'] = parties[n]
                    except IndexError:
                        pass

                    try:
                        kwargs['state'] = states[n]
                    except IndexError:
                        pass

                    if kwargs.get('party') and kwargs.get('state'):
                        legend += ' (%(party)s, %(state)s)' % kwargs
                    elif kwargs.get('party'):
                        legend += ' (%(party)s)' % kwargs
                    elif kwargs.get('state'):
                        legend += ' (%(state)s)' % kwargs

                    legend_items.append(legend)

                    data = handler.read(request, *args, **kwargs)
                    results = data['results']
                    counts = [x.get(key) for x in results]
                    if max(counts) > maxcount:
                        maxcount = max(counts)

                    chart.add_data(counts)
                    metadata.append(kwargs)

                # Duplicated code; should move into separate function.
                if self.request.GET.get('granularity') == 'month':
                    if not months:
                        months = [x['month'] for x in results]
                        januaries = [x for x in months if x.endswith('01')]
                        january_indexes = [months.index(x) for x in januaries]
                        january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]
                        index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
                        chart.set_axis_positions(index, [x for x in january_percentages[::2]])

                chart.y_range = (0, maxcount)

                if key == 'percentage':
                    label = '%.4f' % maxcount
                    label += '%'
                else:
                    label = int(maxcount)

                index = chart.set_axis_labels(Axis.LEFT, [label, ])
                chart.set_axis_positions(index, [100, ])
#.........这里部分代码省略.........
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:103,代码来源:views.py

示例2: lambda_handler

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import y_range [as 别名]
def lambda_handler(event, context):
    # http://developer.yahoo.co.jp/webapi/map/openlocalplatform/v1/weather.html
    
    url = "http://weather.olp.yahooapis.jp/v1/place"
    
    payload = {'appid': YAHOO_APP_ID, 'coordinates': LON + "," + LAT, 'output': 'json'}
    result =  requests.get(url, params=payload)
    
    timeString = getTimeString(30)
    send_message = False
    
    json_data = json.loads(result.content)
    
    rainfall = json_data['Feature'][0]['Property']['WeatherList']['Weather']#[3]['Rainfall']

    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table(inifile.get('dynamodb', 'table_id'))
    key_id = int(inifile.get('dynamodb', 'id_value'))
    result = table.get_item(
        Key={
            'Id': key_id
        }
    )

    if 'raining' not in result:
        table.put_item(
            Item={
                "Id":key_id,
                "raining": False,
                "source": inifile.get('dynamodb', 'source')}
        )
    raining = result['Item']['raining']

    if rainfall[3]['Rainfall'] >= ALERT_THRESH and raining == False:
        send_message = True
        message = timeString + "で" + str(rainfall[3]['Rainfall']) + "mm/hの雨が予想されます。"
    elif rainfall[3]['Rainfall'] < ALERT_THRESH and raining == True:
        send_message = True
        message = timeString + "で" + "雨が止む予報です。"
    elif rainfall[3]['Rainfall'] >= ALERT_THRESH and raining == True:
        send_message = True
        message = timeString + "で" + str(rainfall[3]['Rainfall']) + "mm/hの雨が引き続き降る予報です。"
    elif rainfall[3]['Rainfall'] < ALERT_THRESH and raining == False:
        send_message = False
    
    if rainfall[3]['Rainfall'] >= ALERT_THRESH:
        table.put_item(
            Item={
                "Id":key_id,
                "raining": True,
                "source": inifile.get('dynamodb', 'source')}
        )
    else:
        table.put_item(
            Item={
                "Id":key_id,
                "raining": False,
                "source": inifile.get('dynamodb', 'source')}
        )

    if send_message == True:
    
        width = 500
        height = 150
        chart = SimpleLineChart(width, height)
        chart.set_colours(['719CFF'])
    
        rainfall_array = [rainfall[0]['Rainfall'], rainfall[1]['Rainfall'], rainfall[2]['Rainfall'], rainfall[3]['Rainfall'], rainfall[4]['Rainfall'], rainfall[5]['Rainfall'], rainfall[6]['Rainfall']]
        chart.add_data(rainfall_array)
        
        chart.set_axis_labels(Axis.BOTTOM, [getTimeString(0), getTimeString(10), getTimeString(20), getTimeString(30), getTimeString(40), getTimeString(50), getTimeString(60)])
        chart.set_legend(['Rainfall(mm/h)'])
        chart.set_legend_position('bv')
    
        if math.ceil(max(rainfall_array)) < 1.0:
            chart.y_range=(0, 1)
            chart.set_axis_range(Axis.LEFT, 0, 1)
        else:
            chart.y_range=(0, math.ceil(max(rainfall_array)))
            chart.set_axis_range(Axis.LEFT, 0, math.ceil(max(rainfall_array)))
    
        d = datetime.now() + timedelta(hours=9, minutes=30)
        date_str = d.strftime("|date:%Y%m%d%H%M|datelabel:on")
    
        radar_url = "http://weather.yahoo.co.jp/weather/zoomradar/?lat=" + LAT + "&lon=" + LON + "&z=12"
        rainfall_image_url = getRainfallRadarUrl(LAT, LON, ZOOM, MAP_IMAGE_X, MAP_IMAGE_Y) + date_str
    
        chart_url = shorten_url(chart.get_url())
        rainfall_image_url = shorten_url(rainfall_image_url)
        radar_url = shorten_url(radar_url)
    
        message = unicode(message, 'utf-8') + "\n" + chart_url + "\n" + timeString + u"の雨雲予想: " + rainfall_image_url + "\n" + u"詳細: " + radar_url + "\n"
    
        sc = SlackClient(inifile.get('slack', 'token'))
        res = sc.api_call("chat.postMessage", channel=inifile.get('slack', 'channel'), text=message, username=inifile.get('slack', 'username'), icon_emoji=inifile.get('slack', 'icon_emoji'))
        print(res)
开发者ID:kter,项目名称:rainfallforcast,代码行数:98,代码来源:main.py


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