本文整理汇总了Python中pygal.Pie类的典型用法代码示例。如果您正苦于以下问题:Python Pie类的具体用法?Python Pie怎么用?Python Pie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pie_serie_radius
def test_pie_serie_radius():
pie = Pie()
pie.js = ('http://a.zi:2343/2.0.x/pygal-tooltips.js', )
for i in range(10):
pie.add(str(i), i, inner_radius=(10 - i) / 10)
return pie.render_response()
示例2: test_64_colors
def test_64_colors():
n = 64
colors = [rotate('#ff0000', i * 360 / n) for i in range(n)]
pie = Pie(style=Style(colors=colors))
for i in range(n):
pie(1, title=str(i) if i % 5 == 1 else None)
return pie.render_response()
示例3: test_64_colors
def test_64_colors():
n = 64
colors = [rotate('#ff0000', i * 360 / n) for i in range(n)]
pie = Pie(style=Style(colors=colors))
for i in range(n):
pie.add(str(i), 1)
return pie.render_response()
示例4: node_apply_end
def node_apply_end(repo, node, duration=None, interactive=None, result=None, **kwargs):
if environ.get('TERM_PROGRAM', None) != "iTerm.app" or not interactive:
LOG.debug("skipping iTerm stats (wrong terminal)")
return
if not IMPORTS:
LOG.error("failed to import dependencies of itermstats plugin")
return
css_file = NamedTemporaryFile(delete=False)
css_file.write(".text-overlay { display: none; }")
css_file.close()
config = Config(
height=150,
style=STYLE,
width=350,
)
config.css.append(css_file.name)
chart = Pie(config)
chart.add('correct', result.correct)
chart.add('fixed', result.fixed)
chart.add('skipped', result.skipped)
chart.add('failed', result.failed)
png_data = cairosvg.svg2png(bytestring=chart.render())
png_data_b64 = b64encode(png_data)
remove(css_file.name)
print("\033]1337;File=inline=1:{}\007".format(png_data_b64))
示例5: __init__
def __init__(self):
Pie.__init__(self, inner_radius=0.5,
style=CUSTOM_STYLE, show_legend=False)
self.title = "Distribution"
for label in MoodItem.objects.order_by("order"):
value = Mood.objects(user=current_user.id, mood=label).count()
self.add(label.__str__(),
[{"value": value, "color": label.color}])
print(Mood.objects(user=current_user.id, mood=label).to_json())
示例6: create_pie_chart
def create_pie_chart(self, data=None, span='all', no=None):
"""Creates a pie chart from the the data"""
# Create the list of objects to be added to the chart
chart_list = []
# If the span has been specified, then get the logs only for that time
if not span == None and not span == 'all':
# Iterate through the log data.
for log in self.data:
# Get and format the information we need from the log.
activity = log[0]
log_start = unformat_time(tuple_time(log[1]))
log_end = unformat_time(tuple_time(log[2]))
color = log[3]
minimum = unformat_time(span[1])
maximum = unformat_time(span[2])
# Add the time and activity to the chart_list.
log_time = time_in_span(log_start, log_end, minimum, maximum)
# Check if the activity has already been added to chart_list.
in_chart_list = False
for entry in chart_list:
# If the activity is in the chart_list, make a note and add.
# its time to the existing list item.
if entry[0] == activity:
entry[1] += log_time
in_chart_list = True
# If the log is not in the chart_list and it is in the span, add
# it to the chart_list.
if not in_chart_list and log_time > 0:
chart_list.append([activity, log_time, color])
else:
# If span is not specified then the data are totals.
# Set the chart_list equal to the total data.
for total in data:
chart_list.append((total[0], total[2], total[3]))
# Add each entry is the chart_list to the chart
self.sort(chart_list)
# Data must be organized for day, month, etc. before using
# If size has been specified
if not self.size == (None, None):
self.chart = Pie(style=self.style,
print_values=False,
fill=True,
human_readable=True,
include_x_axis=True,
width=self.size[0],
height=self.size[1])
# If size has not already been specified
else:
# Let the graph dynamically resize within webview
self.chart = Pie(style=self.style, print_values=False, fill=True,
human_readable=True, include_x_axis=True)
if not chart_list == []:
for entry in chart_list:
self.chart.add(entry[0], entry[1])
示例7: create_bar_chart
def create_bar_chart(self, data, span):
"""Creates a bar chart from the the data"""
# Initialize the chart_list
chart_list = []
for log in data:
activity_time = 0
activity = log[0]
log_start = unformat_time(tuple_time(log[1]))
log_end = unformat_time(tuple_time(log[2]))
color = log[3]
minimum = span[1]
maximum = span[2]
minimum = unformat_time(minimum)
maximum = unformat_time(maximum)
activity_time += time_in_span(log_start, log_end, minimum, maximum)
in_chart_list = False
for entry in chart_list:
if entry[0] == activity:
entry[1] += activity_time
in_chart_list = True
if not in_chart_list and activity_time > 0:
chart_list.append([activity, activity_time, color])
self.sort(chart_list)
# Data must be organized for day, month, etc. before using
# If size has been specified
if not self.size == (None, None):
self.chart = Bar(style=self.style, y_scale=60.0,
print_values=False, include_x_axis=True,
width=self.size[0], height=self.size[1])
# If size has not already been specified
else:
# Let the graph dynamically resize within webview
self.chart = Bar(style=self.style, print_values=False,
include_x_axis=True, y_scale=60.0)
self.set_y_labels(chart_list)
## Add each entry is the chart_list to the chart
if not chart_list == []:
for entry in chart_list:
time = str(timedelta(seconds=entry[1]))
if time[1] == ':':
time = '0' + time
self.chart.add(entry[0], [{'value':entry[1], 'label':time}])
else:
self.chart = Pie(style=self.style, width=self.size[0],
height=self.size[1])
示例8: _generate_pie_chart
def _generate_pie_chart(self, datas):
"""
After generate the pie chart,save to file and return the chart path
Keyword arguments:
datas -- Dict object of parsed information for a pie chart
"""
if not datas:
return ""
pie_chart = Pie(fill=True, interpolate="cubic", style=LightStyle)
for key, value in datas.items():
pie_chart.add(key, value)
path = os.path.join(tempfile.gettempdir(), "pie{}.svg".format(str(int(time.time()))))
pie_chart.render_to_file(path)
logging.info("Pie chart was created successfully.")
return path
示例9: test_half_pie
def test_half_pie():
pie = Pie(half_pie=True)
for i in range(20):
pie.add(str(i), i, inner_radius=.1)
pie.legend_at_bottom = True
pie.legend_at_bottom_columns = 4
return pie.render_response()
示例10: test_pie_serie_radius
def test_pie_serie_radius():
pie = Pie()
for i in range(10):
pie.add(str(i), i, inner_radius=(10 - i) / 10)
return pie.render_response()
示例11: __init__
#.........这里部分代码省略.........
# Iterate through the log data.
for log in self.data:
# Get and format the information we need from the log.
activity = log[0]
log_start = unformat_time(tuple_time(log[1]))
log_end = unformat_time(tuple_time(log[2]))
color = log[3]
minimum = unformat_time(span[1])
maximum = unformat_time(span[2])
# Add the time and activity to the chart_list.
log_time = time_in_span(log_start, log_end, minimum, maximum)
# Check if the activity has already been added to chart_list.
in_chart_list = False
for entry in chart_list:
# If the activity is in the chart_list, make a note and add.
# its time to the existing list item.
if entry[0] == activity:
entry[1] += log_time
in_chart_list = True
# If the log is not in the chart_list and it is in the span, add
# it to the chart_list.
if not in_chart_list and log_time > 0:
chart_list.append([activity, log_time, color])
else:
# If span is not specified then the data are totals.
# Set the chart_list equal to the total data.
for total in data:
chart_list.append((total[0], total[2], total[3]))
# Add each entry is the chart_list to the chart
self.sort(chart_list)
# Data must be organized for day, month, etc. before using
# If size has been specified
if not self.size == (None, None):
self.chart = Pie(style=self.style,
print_values=False,
fill=True,
human_readable=True,
include_x_axis=True,
width=self.size[0],
height=self.size[1])
# If size has not already been specified
else:
# Let the graph dynamically resize within webview
self.chart = Pie(style=self.style, print_values=False, fill=True,
human_readable=True, include_x_axis=True)
if not chart_list == []:
for entry in chart_list:
self.chart.add(entry[0], entry[1])
def create_bar_chart(self, data, span):
"""Creates a bar chart from the the data"""
# Initialize the chart_list
chart_list = []
for log in data:
activity_time = 0
activity = log[0]
log_start = unformat_time(tuple_time(log[1]))
log_end = unformat_time(tuple_time(log[2]))
color = log[3]
minimum = span[1]
maximum = span[2]
minimum = unformat_time(minimum)
maximum = unformat_time(maximum)
activity_time += time_in_span(log_start, log_end, minimum, maximum)
in_chart_list = False
for entry in chart_list:
示例12: test_pie_table
def test_pie_table():
"""Test rendering a table for a pie"""
chart = Pie(inner_radius=.3, pretty_print=True)
chart.title = 'Browser usage in February 2012 (in %)'
chart.add('IE', 19.5)
chart.add('Firefox', 36.6)
chart.add('Chrome', 36.3)
chart.add('Safari', 4.5)
chart.add('Opera', 2.3)
q = pq(chart.render_table())
assert len(q('table')) == 1
示例13: test_multiseries_donut
def test_multiseries_donut():
#this just demos that the multiseries pie does not respect the inner_radius
file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
if os.path.exists(file_name):
os.remove(file_name)
chart = Pie(inner_radius=.3, pretty_print=True)
chart.title = 'Browser usage by version in February 2012 (in %)'
chart.add('IE', [5.7, 10.2, 2.6, 1])
chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6])
chart.add('Safari', [4.4, .1])
chart.add('Opera', [.1, 1.6, .1, .5])
chart.render_to_file(file_name)
with open(file_name) as f:
assert 'pygal' in f.read()
os.remove(file_name)
示例14: test_donut
def test_donut():
file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
if os.path.exists(file_name):
os.remove(file_name)
chart = Pie(inner_radius=.3, pretty_print=True)
chart.title = 'Browser usage in February 2012 (in %)'
chart.add('IE', 19.5)
chart.add('Firefox', 36.6)
chart.add('Chrome', 36.3)
chart.add('Safari', 4.5)
chart.add('Opera', 2.3)
chart.render_to_file(file_name)
with open(file_name) as f:
assert 'pygal' in f.read()
os.remove(file_name)
示例15: test_donut
def test_donut():
chart = Pie(inner_radius=0.3, pretty_print=True)
chart.title = "Browser usage in February 2012 (in %)"
chart.add("IE", 19.5)
chart.add("Firefox", 36.6)
chart.add("Chrome", 36.3)
chart.add("Safari", 4.5)
chart.add("Opera", 2.3)
assert chart.render()