mirror of https://github.com/Kozea/pygal.git
Python to generate nice looking SVG graph
http://pygal.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
3.2 KiB
134 lines
3.2 KiB
17 years ago
|
import sys, os
|
||
17 years ago
|
from svg.charts.plot import Plot
|
||
17 years ago
|
g = Plot({
|
||
17 years ago
|
'min_x_value': 0,
|
||
|
'min_y_value': 0,
|
||
|
'area_fill': True,
|
||
|
'stagger_x_labels': True,
|
||
|
'stagger_y_labels': True,
|
||
|
'show_x_guidelines': True
|
||
17 years ago
|
})
|
||
|
g.add_data({'data': [1, 25, 2, 30, 3, 45], 'title': 'series 1'})
|
||
|
g.add_data({'data': [1,30, 2, 31, 3, 40], 'title': 'series 2'})
|
||
|
g.add_data({'data': [.5,35, 1, 20, 3, 10.5], 'title': 'series 3'})
|
||
17 years ago
|
res = g.burn()
|
||
17 years ago
|
f = open(r'Plot.py.svg', 'w')
|
||
|
f.write(res)
|
||
17 years ago
|
f.close()
|
||
|
|
||
17 years ago
|
from svg.charts import time_series
|
||
17 years ago
|
|
||
17 years ago
|
g = time_series.Plot({})
|
||
17 years ago
|
|
||
|
g.timescale_divisions = '4 hours'
|
||
|
g.stagger_x_labels = True
|
||
17 years ago
|
g.x_label_format = '%d-%b %H:%M'
|
||
|
g.max_y_value = 200
|
||
17 years ago
|
|
||
17 years ago
|
g.add_data({'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21], 'title': 'series 1'})
|
||
17 years ago
|
|
||
|
res = g.burn()
|
||
|
|
||
17 years ago
|
f = open(r'TimeSeries.py.svg', 'w')
|
||
|
f.write(res)
|
||
17 years ago
|
f.close()
|
||
17 years ago
|
|
||
17 years ago
|
from svg.charts import bar
|
||
17 years ago
|
|
||
17 years ago
|
fields = ['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']
|
||
|
|
||
17 years ago
|
g = bar.VerticalBar(fields)
|
||
17 years ago
|
|
||
17 years ago
|
g.stack = 'side'
|
||
|
g.scale_integers = True
|
||
|
g.width, g.height = 640,480
|
||
17 years ago
|
g.graph_title = 'Question 7'
|
||
|
g.show_graph_title = True
|
||
17 years ago
|
|
||
17 years ago
|
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
|
||
|
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
|
||
17 years ago
|
|
||
17 years ago
|
open(r'VerticalBar.py.svg', 'w').write(g.burn())
|
||
|
|
||
17 years ago
|
g = bar.HorizontalBar(fields)
|
||
17 years ago
|
|
||
|
g.stack = 'side'
|
||
|
g.scale_integers = True
|
||
|
g.width, g.height = 640,480
|
||
|
g.graph_title = 'Question 7'
|
||
|
g.show_graph_title = True
|
||
|
|
||
17 years ago
|
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
|
||
|
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
|
||
17 years ago
|
|
||
|
open(r'HorizontalBar.py.svg', 'w').write(g.burn())
|
||
|
|
||
17 years ago
|
g = bar.VerticalBar(fields)
|
||
17 years ago
|
options = dict(
|
||
|
scale_integers=True,
|
||
|
stack='side',
|
||
|
width=640,
|
||
|
height=480,
|
||
|
graph_title='Question 8',
|
||
|
show_graph_title=True,
|
||
17 years ago
|
no_css=False,)
|
||
17 years ago
|
g.__dict__.update(options)
|
||
|
|
||
|
g.add_data(dict(data=[2,22,98,143,82], title='intermediate'))
|
||
|
g.add_data(dict(data=[2,26,106,193,105], title='old'))
|
||
|
open('VerticalBarLarge.py.svg', 'w').write(g.burn())
|
||
17 years ago
|
|
||
17 years ago
|
from svg.charts import pie
|
||
|
g = pie.Pie({})
|
||
17 years ago
|
options = dict(
|
||
|
width=640,
|
||
|
height=480,
|
||
|
fields=fields,
|
||
|
graph_title='Question 7',
|
||
|
expand_greatest = True,
|
||
|
show_data_labels = True,
|
||
|
)
|
||
|
g.__dict__.update(options)
|
||
17 years ago
|
g.add_data({'data': [-2, 3, 1, 3, 1], 'title': 'Female'})
|
||
|
g.add_data({'data': [0, 2, 1, 5, 4], 'title': 'Male'})
|
||
17 years ago
|
|
||
17 years ago
|
open('Pie.py.svg', 'w').write(g.burn())
|
||
|
|
||
17 years ago
|
from svg.charts import schedule
|
||
17 years ago
|
|
||
|
title = "Billy's Schedule"
|
||
|
data1 = [
|
||
|
"History 107", "5/19/04", "6/30/04",
|
||
|
"Algebra 011", "6/2/04", "8/11/04",
|
||
|
"Psychology 101", "6/28/04", "8/9/04",
|
||
|
"Acting 105", "7/7/04", "8/16/04"
|
||
|
]
|
||
|
|
||
17 years ago
|
g = schedule.Schedule(dict(
|
||
17 years ago
|
width = 640,
|
||
|
height = 480,
|
||
|
graph_title = title,
|
||
|
show_graph_title = True,
|
||
|
key = False,
|
||
|
scale_x_integers = True,
|
||
|
scale_y_integers = True,
|
||
|
show_data_labels = True,
|
||
|
show_y_guidelines = False,
|
||
|
show_x_guidelines = True,
|
||
17 years ago
|
# show_x_title = True, # not yet implemented
|
||
17 years ago
|
x_title = "Time",
|
||
|
show_y_title = False,
|
||
|
rotate_x_labels = True,
|
||
|
rotate_y_labels = False,
|
||
|
x_label_format = "%m/%d",
|
||
|
timescale_divisions = "1 week",
|
||
|
add_popups = True,
|
||
|
popup_format = "%m/%d/%y",
|
||
|
area_fill = True,
|
||
|
min_y_value = 0,
|
||
|
))
|
||
|
|
||
|
g.add_data(dict(data=data1, title="Data"))
|
||
|
|
||
|
f = open('Schedule.py.svg', 'w').write(g.burn())
|