本文整理汇总了Python中pygooglechart.SimpleLineChart.set_axis_positions方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.set_axis_positions方法的具体用法?Python SimpleLineChart.set_axis_positions怎么用?Python SimpleLineChart.set_axis_positions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygooglechart.SimpleLineChart
的用法示例。
在下文中一共展示了SimpleLineChart.set_axis_positions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _partyline
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [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()
示例2: simpleChart3
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [as 别名]
def simpleChart3(bottom_labels, data1, data2):
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)
return chart
示例3: simpleChart1
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [as 别名]
def simpleChart1(bottom_labels, data):
# round min and max to nearest integers
datamin = int(min(data) - 0.5)
datamax = int(max(data) + 0.5)
chart = SimpleLineChart(200, 125, y_range=[datamin, datamax])
chart.add_data(data)
left_axis = [datamin,0,datamax]
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
return chart
示例4: _line
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [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()
示例5: cat_proximity
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [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')
示例6: simpleChart2
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [as 别名]
def simpleChart2(bottom_labels, data):
# round min and max to nearest integers
datamin = int(min(data) - 0.5)
datamax = int(max(data) + 0.5)
chart = SimpleLineChart(200, 125, y_range=[datamin, datamax])
chart.add_data(data)
left_axis = ['min',0,'max']
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'])
# 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)
return chart
示例7: int
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [as 别名]
chart.set_colours(['000000'])
# fill in the elevation area with a hex color
chart.add_fill_range('80C65A', 1, 2)
# Set up labels for the minimum elevation, halfway value, and max value
elv_labels = int(round(min(elvs))), int(min(elvs)+((max(elvs)-min(elvs)/2))), \
int(round(max(elvs)))
# Assign the labels to an axis
elv_label = chart.set_axis_labels(Axis.LEFT, elv_labels)
# Label the axis
elv_text = chart.set_axis_labels(Axis.LEFT, ["FEET"])
# Place the label at 30% the distance of the line
chart.set_axis_positions(elv_text, [30])
# Calculate distances between track segments
distances = []
measurements = []
coords = list(zip(lons, lats))
for i in range(len(coords)-1):
x1, y1 = coords[i]
x2, y2 = coords[i+1]
d = haversine(x1, y1, x2, y2)
distances.append(d)
total = sum(distances)
distances.append(0)
j =- 1
# Locate the mile markers
示例8: read
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [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, ])
#.........这里部分代码省略.........
示例9: createChart
# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import set_axis_positions [as 别名]
def createChart(title, xaxis, datay, firstweekday):
# Find the max y value
max_y = None
for dd in datay.values():
max_y = max(max_y, max(dd))
# Chart size of 400x250 pixels and specifying the range for the Y axis
if title:
chart = SimpleLineChart(1000, 250, title=title, y_range=[0, max_y])
else:
chart = SimpleLineChart(1000, 250, y_range=[0, max_y])
# 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
#.........这里部分代码省略.........