本文整理汇总了Python中pygooglechart.SimpleLineChart.set_legend方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.set_legend方法的具体用法?Python SimpleLineChart.set_legend怎么用?Python SimpleLineChart.set_legend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygooglechart.SimpleLineChart
的用法示例。
在下文中一共展示了SimpleLineChart.set_legend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simpleChart3legend
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def simpleChart3legend(bottom_labels, data1, legend1, data2, legend2):
datamin, datamax = min(min(data1, data2)), max(max(data1, data2))
datamin = int(datamin - 0.5)
datamax = int(datamax + 0.5)
chart = SimpleLineChart(200, 125, y_range=[datamin, datamax])
chart.add_data(data1)
chart.add_data(data2)
left_axis = [datamin,0,datamax]
left_axis[0] = '' # no label at 0
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.set_axis_labels(Axis.BOTTOM, bottom_labels)
chart.set_axis_labels(Axis.BOTTOM, ['X Axis']) # second label below first one
chart.set_axis_positions(2, [50.0]) # position, left is 0., right is 100., 50. is center
# Set the line colour
chart.set_colours(['0000FF', 'FF0000'])
# Set the horizontal dotted lines
chart.set_grid(0, 25, 5, 5)
# Set vertical stripes
stripes = ['CCCCCC', 0.2, 'FFFFFF', 0.2]
chart.fill_linear_stripes(Chart.CHART, 0, *stripes)
# legend
chart.set_legend([legend1, legend2])
return chart
示例2: _partyline
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def _partyline(self, party_results):
if self.request.GET.get('percentages') == 'true':
key = 'percentage'
else:
key = 'count'
maxcount = 0
allcounts = []
granularity = self.request.GET.get('granularity')
months = []
for party, results in party_results.iteritems():
counts = [x.get(key) for x in results['results']]
allcounts.append(counts)
if max(counts) > maxcount:
maxcount = max(counts)
if granularity == 'month':
months = [x['month'] for x in results['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]
#times = [x.get(granularity) for x in results['results']]
width = int(self.request.GET.get('width', 575))
height = int(self.request.GET.get('height', 318))
chart = SimpleLineChart(width, height, y_range=(0, max(counts)))
chart.fill_solid('bg', '00000000') # Make the background transparent
chart.set_grid(0, 50, 2, 5) # Set gridlines
if granularity == 'month':
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]])
if key == 'percentage':
label = '%.4f' % maxcount
else:
label = int(maxcount)
index = chart.set_axis_labels(Axis.LEFT, [label, ])
chart.set_axis_positions(index, [100, ])
for n, counts in enumerate(allcounts):
chart.add_data(counts)
chart.set_line_style(n, thickness=2) # Set line thickness
colors = {'R': 'bb3110', 'D': '295e72', }
chart_colors = []
chart_legend = []
for k in party_results.keys():
chart_colors.append(colors.get(k, '000000'))
chart_legend.append(k)
chart.legend_position = 'b'
chart.set_colours(chart_colors)
if self.request.GET.get('legend', 'true') != 'false':
chart.set_legend(chart_legend)
return chart.get_url()
示例3: __init__
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
class DiceChart:
chart = None
def __init__(self, data, iter=0, width=300, height=300):
self.chart = SimpleLineChart(width, height, y_range=(0, 10))
legend = []
colors = ["cc0000", "00cc00", "0000cc", "990000", "009900", "000099", "0099ff", "FF9900", "9900ff", "ff0099"]
title = "die rolls per objective"
if iter > 0:
title = title + " (%s samples)" % iter
for i in data.keys():
self.chart.add_data(data[i])
legend.append(str(i))
logging.debug(legend)
logging.debug(colors)
self.chart.set_colours(colors)
self.chart.set_legend(legend)
grid_x_amount = 100 / (len(data[i]) - 1)
self.chart.set_grid(grid_x_amount, 10, 5, 5)
left_axis = range(0, 11, 1)
left_axis[0] = ""
self.chart.set_axis_labels(Axis.LEFT, left_axis)
bottom_len = len(data[i]) + 2
bottom_axis = range(2, bottom_len, 1)
self.chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
self.chart.set_title(title)
def download(self, name="dicechart.png"):
self.chart.download(name)
示例4: getLineGraph
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [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()
示例5: velocity_chart
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [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)
示例6: get
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def get(self):
counters = tasks.Counter.all().fetch(10)
rows = [{'name':c.key().name(), 'count':c.count} for c in counters]
chart = SimpleLineChart(1000, 300)
for counter in counters:
query = counter.snapshots
query.order('-date')
snapshots = query.fetch(30)
counts = [s.count for s in snapshots]
dates = [s.date.strftime("%d/%m") for s in snapshots]
for i in xrange(len(counts) - 1):
counts[i] -= counts[i+1]
counts.reverse()
dates.reverse()
chart.add_data(counts[1:])
chart.set_axis_labels(pygooglechart.Axis.BOTTOM, dates[1:])
chart.set_axis_labels(pygooglechart.Axis.LEFT, range(0, chart.data_y_range()[1], 5))
hsv_colours = [(float(x) / 255, 1, 1) for x in range(0, 255, 255 / len(counters))]
rgb_colours = [colorsys.hsv_to_rgb(*x) for x in hsv_colours]
hex_colours = ['%02x%02x%02x' % (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)) for x in rgb_colours]
chart.set_colours(hex_colours)
chart.set_legend([c.key().name() for c in counters])
path = os.path.join(os.path.dirname(__file__), self.TEMPLATE)
self.response.out.write(template.render(path,
{ 'url': chart.get_url(),
'counters': rows }))
示例7: simple_line
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def simple_line():
chart = SimpleLineChart(settings.width, settings.height,
x_range=(0, 35))
chart.set_colours(['00ff00', 'ff0000','ACff0C','B0ffE0','C0ffFF'])
chart.add_data([1,2,3,4,5])
chart.add_data([1,4,9,16,25])
chart.set_title('This is title')
chart.set_axis_labels('r', 'str')
chart.set_legend( ['a','b','c','d','e'])
chart.download('simple-line.png')
示例8: generate_freq_chart_url_from_qset
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def generate_freq_chart_url_from_qset(qset, sizex, sizey):
''' returns url for chart from given queryset '''
end_year = qset.order_by('-publication_date')[0].publication_date.year
start_year = qset.order_by('publication_date')[0].publication_date.year
#print "start {0}, end {1}".format(start_year, end_year)
year_range=range(start_year,end_year + 1)
month_range=range(1, 13)
count_rules = []
count_proprules = []
count_notices = []
count_presdocs = []
count_unknown = []
count_total = []
today = datetime.date.today()
for y in year_range:
start_date=datetime.date(y,1,1)
end_date=datetime.date(y,12,31)
year_qset = qset.filter(publication_date__range=(start_date, end_date))
count_rules.append(year_qset.filter(document_type='Rule').count())
count_proprules.append(year_qset.filter(document_type='Proposed Rule').count())
count_notices.append(year_qset.filter(document_type='Notice').count())
count_presdocs.append(year_qset.filter(document_type='Presidential Document').count())
count_unknown.append(year_qset.filter(document_type='Document of Unknown Type').count())
count_total.append(count_unknown[-1] + count_presdocs[-1] + count_rules[-1] + count_proprules[-1] + count_notices[-1])
#for i in [count_rules, count_proprules, count_notices, count_presdocs, count_unknown, count_total]:
#print i
# set up chart axis parameters
largest_y = max(count_total)
left_axis_step = int(pow(10, int(log10(largest_y))))
max_y = (int(largest_y / left_axis_step) * left_axis_step) + (left_axis_step * 2)
left_axis = range(0, max_y + left_axis_step, left_axis_step)
left_axis[0] = ""
bottom_axis = year_range
# generate chart url
chart = SimpleLineChart(sizex, sizey, y_range=[0, max_y])
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
chart.set_grid(0, max(10, int(left_axis_step / 10)), 5, 5)
chart.set_colours(['0000FF', '00FF00', 'FF0000', 'FFFF00', '00FFFF', 'aaaaaa'])
chart.set_legend(['Rules', 'Proposed Rules', 'Notices', 'Presidential Docs', 'Unknown', 'Total'])
chart.add_data(count_rules)
chart.add_data(count_proprules)
chart.add_data(count_notices)
chart.add_data(count_presdocs)
chart.add_data(count_unknown)
chart.add_data(count_total)
chart_url = chart.get_url()
return chart_url
示例9: _line_strip_graph
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [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
示例10: group_post_activity
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [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()
示例11: linechart
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def linechart(name, dataset, size=(400,400)):
max_y = maxy(dataset)
chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y])
legend = []
for series_name, s in dataset:
chart.add_data([y for x, y in s])
legend.append(series_name)
chart.set_colours(['057D9F', '8106A9', 'E9FB00', 'FF8100'])
chart.set_legend(legend)
chart.set_grid(0, 25, 5, 5)
left_axis = range(0, int(max_y + 1), 25)
left_axis[0] = ''
chart.set_axis_labels(Axis.LEFT, left_axis)
bottom_axis = [x for x, y in dataset[0][1]]
chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
chart.download(name)
示例12: _line
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def _line(self, results):
key = 'count'
if self.request.GET.get('percentages') == 'true':
key = 'percentage'
counts = [x.get(key) for x in results]
maxcount = max(counts)
granularity = self.request.GET.get('granularity')
times = [x.get(granularity) for x in results]
width = int(self.request.GET.get('width', 575))
height = int(self.request.GET.get('height', 300))
chart = SimpleLineChart(width, height, y_range=(0, max(counts)))
chart.add_data(counts)
chart.set_line_style(0, thickness=2) # Set line thickness
chart.set_colours(['E0B300', ])
chart.fill_solid('bg', '00000000') # Make the background transparent
chart.set_grid(0, 50, 2, 5) # Set gridlines
if self.request.GET.get('granularity') == 'month':
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]])
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, ])
if self.request.GET.get('legend', 'true') != 'false':
chart.set_legend([self.request.GET.get('phrase'), ])
return chart.get_url()
示例13: cat_proximity
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
def cat_proximity():
"""Cat proximity graph from http://xkcd.com/231/"""
chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])
# intelligence
data_index = chart.add_data([100. / y for y in xrange(1, 15)])
# insanity of statements
chart.add_data([100. - 100 / y for y in xrange(1, 15)])
# line colours
chart.set_colours(['208020', '202080'])
# "Near" and "Far" labels, they are placed automatically at either ends.
near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])
# "Human Proximity to cat" label. Aligned to the center.
index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
chart.set_axis_style(index, '202020', font_size=10, alignment=0)
chart.set_axis_positions(index, [50])
chart.download('label-cat-proximity.png')
示例14: __line_strip_graphic__
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [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
示例15: generate_trophy_freq_chart_url
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_legend [as 别名]
#.........这里部分代码省略.........
# get yearly counts
years_with_counts = {}
for t in lancaster_t:
for k,v in t.iteritems():
if k =='app_date':
try:
lancaster_years_with_counts[v.year] += 1
except KeyError:
lancaster_years_with_counts[v.year] = 1
try:
maxyear = max(v.year, maxyear)
minyear = min(v.year, minyear)
except:
minyear = v.year
maxyear = v.year
# get yearly counts
years_with_counts = {}
for t in sbeaufort_t:
for k,v in t.iteritems():
if k =='app_date':
try:
sbeaufort_years_with_counts[v.year] += 1
except KeyError:
sbeaufort_years_with_counts[v.year] = 1
try:
maxyear = max(v.year, maxyear)
minyear = min(v.year, minyear)
except:
minyear = v.year
maxyear = v.year
# get yearly counts
years_with_counts = {}
for t in nbeaufort_t:
for k,v in t.iteritems():
if k =='app_date':
try:
nbeaufort_years_with_counts[v.year] += 1
except KeyError:
nbeaufort_years_with_counts[v.year] = 1
try:
maxyear = max(v.year, maxyear)
minyear = min(v.year, minyear)
except:
minyear = v.year
maxyear = v.year
# get yearly counts
years_with_counts = {}
for t in other_t:
for k,v in t.iteritems():
if k =='app_date':
try:
other_years_with_counts[v.year] += 1
except KeyError:
other_years_with_counts[v.year] = 1
try:
maxyear = max(v.year, maxyear)
minyear = min(v.year, minyear)
except:
minyear = v.year
maxyear = v.year
# assemble year counts in ordered series
for y in range(minyear, maxyear + 1):
try:
lancaster_counts.append(lancaster_years_with_counts[y])
except:
lancaster_counts.append(0)
try:
other_counts.append(other_years_with_counts[y])
except:
other_counts.append(0)
try:
nbeaufort_counts.append(nbeaufort_years_with_counts[y])
except:
nbeaufort_counts.append(0)
try:
sbeaufort_counts.append(sbeaufort_years_with_counts[y])
except:
sbeaufort_counts.append(0)
# set up chart url
for y in range(minyear, maxyear + 1):
bottom_axis.append(y)
max_count = max(max(sbeaufort_counts), max(nbeaufort_counts), max(other_counts), max(lancaster_counts))
left_axis = range(0, max_count, 10)
chart = SimpleLineChart(sizex, sizey, y_range=[0, max_count])
chart.set_colours(['FFFF00', 'FF0000', '00FF00', '0000FF'])
chart.set_legend(['Lancaster Sound', 'Northern Beaufort Sea', 'Southern Beaufort Sea', 'Other'])
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
chart.add_data(lancaster_counts)
chart.add_data(nbeaufort_counts)
chart.add_data(sbeaufort_counts)
chart.add_data(other_counts)
chart_url = chart.get_url()
return chart_url