本文整理汇总了Python中pygooglechart.SimpleLineChart.set_legend_position方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.set_legend_position方法的具体用法?Python SimpleLineChart.set_legend_position怎么用?Python SimpleLineChart.set_legend_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygooglechart.SimpleLineChart
的用法示例。
在下文中一共展示了SimpleLineChart.set_legend_position方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLineGraph
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def getLineGraph(data,line1color,line2color):
# Set the vertical range based on data values
tweets = [d[0] for d in data]
retweets = [d[1] for d in data]
ratio = [str(int(d[1]/d[0]*100))+'%' for d in data]
hours = [d[2] for d in data]
mx = max(tweets)
mn = min(retweets)
buffer = (mx - mn)/100 # average retweets have consitently been less
min_y = mn - buffer
max_y = mx + buffer
# Chart size of 750x400 pixels and specifying the range for the Y axis
chart = SimpleLineChart(750, 400, y_range=[min_y, max_y])
chart.set_legend(['Tweets','Retweets'])
chart.set_legend_position('t')
# Add the chart data
chart.add_data(tweets)
chart.add_data(retweets)
# Set the line colour to blue
chart.set_colours([line1color,line2color])
# Set the horizontal dotted lines
chart.set_grid(0, 25, 5, 5)
#set left axis to values range
left_axis = range(min_y, max_y, (max_y-min_y)/10)
chart.set_axis_labels(Axis.BOTTOM, hours)
chart.set_axis_labels(Axis.BOTTOM, ratio)
chart.set_axis_labels(Axis.LEFT, left_axis)
return chart.get_url()
示例2: velocity_chart
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def velocity_chart(self):
graph_width = 600
graph_height = 300
x_max = self.total_iterations
y_max = max(max(self.estimate_stories_data()),
max(self.estimate_tasks_data()),
max(self.work_data()))
chart = SimpleLineChart(graph_width, graph_height,
x_range=(1, x_max + 1), y_range=(0, y_max + 1))
chart.add_data(self.estimate_stories_data())
chart.add_data(self.estimate_tasks_data())
chart.add_data(self.work_data())
chart.set_grid(0, 100.0 / y_max + 1, 5, 5)
chart.set_colours(['FF0000', '00FF00', '0000FF'])
chart.set_legend([_('rough story estimates'),
_('task estimates'), _('worked')])
chart.set_legend_position('b')
chart.set_axis_labels(Axis.LEFT, ['', '', _('days')])
chart.set_axis_labels(Axis.BOTTOM, range(1, x_max + 1))
chart.set_axis_range(Axis.LEFT, 0, y_max + 1)
return chart.get_url(data_class=ExtendedData)
示例3: _line_strip_graph
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def _line_strip_graph(data, legends, axis_labels, size, steps,
type=SimpleLineChart, multiline=False):
if multiline:
max_values = []
min_values = []
for row in data:
max_values.append(max(row))
min_values.append(min(row))
max_y = max(max_values)
min_y = min(min_values)
else:
max_y = max(data)
min_y = min(data)
#validando si hay datos para hacer grafico
if max_y==0:
return None
chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y*1.05])
if multiline:
for row in data:
chart.add_data(row)
else:
chart.add_data(data)
step = ((max_y*1.05)-(min_y*0.95))/steps
#validando en caso de el paso sea menor que uno y de cero en la conversion
if step<1:
step = 1
tope = int(round(max_value*1.05))
if tope < max_value:
tope+=2
else:
tope+=1
try:
left_axis = range(int(round(min_y*0.95)), tope, int(step))
except ValueError:
#error por que los range no soportan decimales
left_axis = range(0, 2)
left_axis[0]=''
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.set_colours([ 'FFBC13','22A410','E6EC23','2B2133','BD0915','3D43BD'])
chart.set_axis_labels(Axis.BOTTOM, axis_labels)
chart.set_legend(legends)
chart.set_legend_position('b')
return chart
示例4: group_post_activity
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def group_post_activity(request, group_slug):
group = get_object_or_404(BaseGroup, slug=group_slug)
postcount = []
replycount = []
allcount = []
listdate = []
thedate = date(date.today().year - 1,
date.today().month,
1)
skip = False
while thedate.year != date.today().year or thedate.month != date.today().month:
if thedate.month == 12:
enddate = date(year=thedate.year + 1,
month=1, day=1)
else:
enddate = date(year=thedate.year,
month=thedate.month + 1,
day=1)
posts = GroupTopic.objects.filter(parent_group=group,
created__range=(thedate, enddate)).count()
#replies = ThreadedComment.objects.filter(content_object__parent_group=group,
# date_submitted__range=(thedate, enddate)).count()
replies = 0
postcount.append(posts)
replycount.append(replies)
allcount.append(posts + replies)
if not skip:
listdate.append(thedate.strftime("%B %y"))
else:
listdate.append("")
skip = not skip
thedate = enddate
postactivity = SimpleLineChart(600, 450, y_range=(min(min(postcount), min(replycount)), max(max(postcount), max(replycount)) + 1))
postactivity.add_data(postcount)
postactivity.add_data(replycount)
postactivity.add_data(allcount)
yaxis = range(min(min(postcount), min(replycount)), max(max(postcount), max(replycount)) + 1, 1)
if len(yaxis) < 2:
yaxis.append(1)
yaxis[0] = ''
postactivity.set_axis_labels(Axis.LEFT, yaxis)
postactivity.set_axis_labels(Axis.BOTTOM, listdate)
postactivity.set_colours(['ff0000', '0000ff', '00ff00'])
postactivity.set_legend(['posts', 'replies', 'total'])
postactivity.set_legend_position('b')
return postactivity.get_url()
示例5: __line_strip_graphic__
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def __line_strip_graphic__(data, legends, axis_labels, size, steps,
type=SimpleLineChart, multiline=False):
if multiline:
max_values = []
min_values = []
for row in data:
max_values.append(max(row))
min_values.append(min(row))
max_y = max(max_values)
min_y = min(min_values)
else:
max_y = max(data)
min_y = min(data)
chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y*1.05])
if multiline:
for row in data:
chart.add_data(row)
else:
chart.add_data(data)
step = ((max_y*1.05)-(min_y*0.95))/steps
try:
left_axis = range(int(min_y*0.95), int(max_y*1.05), int(step))
except ValueError:
#error por que los range no soportan decimales
left_axis = range(0, 2)
left_axis[0]=''
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.set_colours([ 'FFBC13','22A410','E6EC23','2B2133','BD0915','3D43BD'])
chart.set_axis_labels(Axis.BOTTOM, axis_labels)
chart.set_legend(legends)
chart.set_legend_position('b')
return chart
示例6: _line_strip_graph
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def _line_strip_graph(data, legends, axis_labels, size, steps,
type=SimpleLineChart, multiline=False, **kwargs):
if multiline:
max_values = []
min_values = []
for row in data:
max_values.append(max(row))
min_values.append(min(row))
max_y = max(max_values)
min_y = min(min_values)
else:
max_y = max(data)
min_y = min(data)
#validando si hay datos para hacer grafico
if max_y==0:
return None
chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y*1.05])
if multiline:
for row in data:
chart.add_data(row)
else:
chart.add_data(data)
step = ((max_y*1.05)-(min_y*0.95))/steps
#validando en caso de el paso sea menor que uno y de cero en la conversion
if step<1:
step = 1
max_value = max_y
tope = int(round(max_value*1.05))
if tope < max_value:
tope+=2
else:
tope+=1
try:
left_axis = range(int(round(min_y*0.95)), tope, int(step))
except ValueError:
#error por que los range no soportan decimales
left_axis = range(0, 2)
left_axis[0]=''
chart.set_axis_range(Axis.LEFT, min_y, tope)
if 'units' in kwargs:
chart.set_axis_labels(Axis.LEFT, kwargs['units'])
if 'time' in kwargs:
chart.set_axis_labels(Axis.BOTTOM, kwargs['time'])
chart.set_grid(0, 25, 4, 4,)
chart.chls=4|4
#chart.fill_linear_stripes(Chart.CHART, 0, 'FFFFEF', 0.2, 'FFFFFF', 0.2)
chart.set_colours(COLORS)
if axis_labels:
chart.set_axis_labels(Axis.BOTTOM, axis_labels)
chart.set_legend(legends)
chart.set_legend_position('b')
if 'thickness' in kwargs:
if multiline:
for i in range(len(data)):
chart.set_line_style(index = i, thickness=kwargs['thickness'])
else:
chart.set_line_style(index=0, thickness=kwargs['thickness'])
return chart
示例7: main_dashboard
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
def main_dashboard(request):
today, created = DailyStats.objects.get_or_create(day=date.today())
if today.users == 0:
today.users = 1
# ---- Daily usage ----
enddate = date.today()
#startdate = enddate - timedelta(weeks=60)
startdate = enddate - timedelta(weeks=4)
averageusage = DailyStats.objects.filter(day__range=(startdate, enddate)).order_by('day')
days = []
signins = []
posts = []
replies = []
whiteboards = []
signups = []
listsignups = []
listupgrades = []
deletions = []
numUsers = []
numRegularMembers = []
regupgrades = []
renewals = []
regdowngrades = []
for s in averageusage:
days.append(s.day.strftime("%B %y"))
signins.append(s.signins)
posts.append(s.posts)
replies.append(s.replies)
whiteboards.append(s.whiteboardEdits)
signups.append(s.signups)
listsignups.append(s.mailinglistsignups)
listupgrades.append(s.mailinglistupgrades)
deletions.append(s.deletions)
numUsers.append(s.users)
numRegularMembers.append(s.regularmembers)
regupgrades.append(s.regupgrades)
renewals.append(s.renewals)
regdowngrades.append(s.regdowngrades)
xaxis = []
#for i in range(0, len(days), 1): # this will make limited test data look better
for i in range(0, len(days), len(days)/8):
xaxis.append(days[i])
# ---- Daily usage ----
dailyUsageChart = SimpleLineChart(600, 450, y_range=(0, max(signins)))
#chart.add_data(avgsignins)
dailyUsageChart.add_data(posts)
dailyUsageChart.add_data(replies)
dailyUsageChart.add_data(signins)
dailyUsageChart.add_data(whiteboards)
dailyUsageChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
dailyUsageChart.set_legend(['posts', 'replies', 'signins', 'whiteboards'])
dailyUsageChart.set_legend_position('b')
#yaxis = range(0, max_signins + 1, 2) # this will make limited test data look better
yaxis = range(0, max(signins), max(signins)/10)
yaxis[0] = ''
dailyUsageChart.set_axis_labels(Axis.LEFT, yaxis)
dailyUsageChart.set_axis_labels(Axis.BOTTOM, xaxis)
dailyUsage = dailyUsageChart.get_url()
# ---- Account changes ----
accountChangesChart = SimpleLineChart(600, 450, y_range=(0, 25))
accountChangesChart.add_data(signups)
accountChangesChart.add_data(listsignups)
accountChangesChart.add_data(listupgrades)
accountChangesChart.add_data(deletions)
accountChangesChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
accountChangesChart.set_legend(['account signups', 'email signups', 'email upgrades', 'deletions'])
accountChangesChart.set_legend_position('b')
#yaxis = range(0, 25, 2) # this will make limited test data look better
yaxis = range(0, min(max(listsignups), 10), max(max(listsignups)/10, 1))
yaxis[0] = ''
accountChangesChart.set_axis_labels(Axis.LEFT, yaxis)
accountChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)
accountChanges = accountChangesChart.get_url()
# ---- Membership ----
membershipChart = SimpleLineChart(600, 450, y_range=(42000, 52000))
membershipChart.add_data(numUsers)
membershipChart.add_data(numRegularMembers)
membershipChart.set_colours(['ff0000', '0000ff'])
membershipChart.set_legend(['total users', 'regular members'])
membershipChart.set_legend_position('b')
yaxis = range(42000, 52000, 1000)
yaxis[0] = ''
yaxis2 = range(0, 1500, 50)
yaxis2[0] = ''
membershipChart.set_axis_labels(Axis.LEFT, yaxis)
membershipChart.set_axis_labels(Axis.RIGHT, yaxis2)
#.........这里部分代码省略.........
示例8: render
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [as 别名]
#.........这里部分代码省略.........
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:
fill_config = ChartConfig()
fill_config.__dict__.update(serie_config.__dict__)
fill_config.__dict__.update(serie_config.area)
to = ordered_keys.index(fill_config.to)
chart.add_fill_range(_valid_color(fill_config.color), index, to)
if serie_config.dash:
chart.set_line_style(index, serie_config.thickness, serie_config.dash, serie_config.dash)
else:
chart.set_line_style(index, serie_config.thickness)
if serie_config.legend:
legend.append(serie_config.legend)
legend_set = True
else:
legend.append('')
if serie_config.marks:
mark_config = ChartConfig()
mark_config.__dict__.update(serie_config.__dict__)
mark_config.__dict__.update(serie_config.marks)
mark_data = copy.copy(data[mark_config.serie.split('.')[0]]['series'][mark_config.serie.split('.')[1]])
mark_data = compress_to(mark_data, config.nval, min_index, max_index)[0]
for i, m in enumerate(mark_data):
if not m:
mark_data[i] = " "
density = max(1.0, 1.0 * mark_config.space * len("".join(mark_data))*mark_config.size / config.width)
for i, v in enumerate(mark_data):
if (i +1) % round(density) == 0:
if serie_data[i] != 0:
text = str(mark_data[i])
else:
text = " "
chart.add_marker(index, i, 't'+text, _valid_color(mark_config.color), mark_config.size)
index = index + 1
# Compute vertical range
if config.axes:
range_min_ref_units = 0
if not chart_min == sys.maxint and not chart_max == -sys.maxint:
range_min = chart_min-config.ymargin[0]
range_max = chart_max+config.ymargin[1]
range_min_target_units = math.floor(converter.convert(measure, range_min))
range_max_target_units = math.ceil(converter.convert(measure, range_max))
range_min_ref_units = converter.convert_back(measure, range_min_target_units)
range_max_ref_units = converter.convert_back(measure, range_max_target_units)
self.logger.debug("Y range: "+str(range_min_target_units) +" "+str(range_max_target_units))
chart.set_axis_range(Axis.LEFT, range_min_target_units, range_max_target_units+1)
chart.add_data([range_min_ref_units, range_max_ref_units])
colors.append("00000000")
else:
chart.set_axis_range(Axis.LEFT, 0, 100)
chart.set_axis_style(0, _valid_color(config.text), config.size, 0, Axis.BOTH if config.ticks else Axis.AXIS_LINES)
else:
chart.set_axis_labels(Axis.LEFT, [])
chart.set_axis_style(0, _valid_color(config.text), config.size, 0, Axis.TICK_MARKS, _valid_color(config.bgcolor))
if config.zero and config.axes and range_min_ref_units < 0 and range_max_ref_units > 0:
zero_config = ChartConfig()
zero_config.__dict__.update(config.__dict__)
zero_config.__dict__.update(config.zero)
chart.add_data([0]*2)
colors.append(_valid_color(zero_config.color))
chart.set_line_style(index, zero_config.thickness)
chart.set_colours(colors)
chart.fill_solid(Chart.BACKGROUND, _valid_color(config.bgcolor))
if legend_set:
chart.set_legend(legend)
chart.set_legend_position(config.legend_pos)
if self.labels:
labels_data = copy.copy(data[self.labels.split('.')[0]]['series'][self.labels.split('.')[1]])
labels_data = compress_to(labels_data, config.nval, None, None)[0]
if config.axes:
density = 1.0 * len("".join(labels_data))*config.size / config.width
if density > LABEL_DENSITY_THRESHOLD:
for i, v in enumerate(labels_data):
if i % round(density) != 0:
labels_data[i] = ' '
chart.set_axis_labels(Axis.BOTTOM, labels_data)
chart.set_axis_style(1, _valid_color(config.text), config.size, 0, Axis.BOTH if config.ticks else Axis.AXIS_LINES)
else:
chart.set_axis_labels(Axis.BOTTOM, [])
chart.set_axis_style(1, _valid_color(config.text), config.size, 0, Axis.TICK_MARKS, _valid_color(config.color))
try:
return chart.get_url()+"&chma=10,10,10,10" # add a margin
except:
self.logger.exception("Could not render chart")
return "http://chart.apis.google.com/chart?cht=lc&chs="+str(config.width)+"x"+str(config.height)
示例9: lambda_handler
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend_position [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)