pyexcel-pygal - Let you focus on data, instead of file formats¶
Author: | C.W. |
---|---|
Source code: | http://github.com/pyexcel/pyexcel-pygal.git |
Issues: | http://github.com/pyexcel/pyexcel-pygal/issues |
License: | New BSD License |
Released: | 0.0.1 |
Generated: | Aug 20, 2017 |
Introduction¶
pyexcel-pygal is a tiny plugin of pyexcel to turn pyexcel data into chart graphics using pygal.
To see pyexcel-pygal in action with Jupyter notebook, please checkout the resource on github folder
Installation¶
You can install it via pip:
$ pip install pyexcel-pygal
or clone it and install it:
$ git clone https://github.com/pyexcel/pyexcel-pygal.git
$ cd pyexcel-pygal
$ python setup.py install
Content¶
Plot pyexcel data in Jupyter Notebook¶
There are currently four type of data layouts for rendering charts.
1 Simple Layout¶
Series names are placed in the first row. The rest of the rows are data sets.
Pie chart¶
title = 'Browser usage in February 2012 (in %)'
sheet = pyexcel.get_sheet(file_name='pie.csv')
svg = sheet.plot(chart_type='pie',
title=title, width=600, height=400, explicit_size=True)
2 Complex layout¶
On top of previous layout, x labels were inserted as the first column. In other words, each column represents series data and the first column contains x labels. y labels locate in the first row
Line¶
Here is the source code using pyexcel:
title = 'Browser usage evolution (in %)'
sheet = pyexcel.get_sheet(file_name='line.csv')
svg = sheet.plot(chart_type='line',
title=title, width=600, height=400, explicit_size=True)
Dot chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
sheet = pyexcel.get_sheet(file_name='radar.csv')
svg = sheet.plot(chart_type='dot',
title=title, width=600, height=400, explicit_size=True)
Funnel chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
sheet = pyexcel.get_sheet(file_name='funnel.csv')
svg = sheet.plot(chart_type='funnel',
title=title, width=600, height=400, explicit_size=True)
Histogram¶
To draw a histogram, heights, starts and stops should be placed sequentially in first, second and third columns.
Here is the source code using pyexcel:
sheet = pyexcel.get_sheet(file_name='histogram_wide_bars.csv')
svg = sheet.plot(chart_type='histogram',
width=600, height=400, explicit_size=True)
In order to draw multiple histogram on the same chart, you will need to use a Book, each sheet of which become a histogram. Here is how you can draw multiple histogram.
Here is the source code using pyexcel
book = pyexcel.get_book(file_name='histogram.xlsx')
svg = book.plot(chart_type='histogram',
width=600, height=400, explicit_size=True)
XY¶
In order to draw XY graph, x, y data should be placed vertically at first and second column. In order to draw multiple lines, their data should be placed in individual sheets.
Here is the source code using pyexcel
book = pyexcel.get_book(file_name='xy.xlsx')
svg = book.plot(chart_type='xy',
width=600, height=400, explicit_size=True)
Save pyexcel data as svg chart¶
Line¶
Here is the source code using pyexcel:
title = 'Browser usage evolution (in %)'
x_labels = map(str, range(2002, 2013))
data = {
'Firefox': [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1],
'Chrome': [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3], # flake8: noqa
'IE': [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1],
'Others': [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]
}
pe.save_as(
adict=data,
dest_title=title,
dest_x_labels=x_labels,
dest_chart_type='line',
dest_file_name='line.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Line directly
Histogram¶
Here is the source code using pyexcel:
data = {
'Wide bars': [(5, 0, 10), (4, 5, 13), (2, 0, 15)],
'Narrow bars': [(10, 1, 2), (12, 4, 4.5), (8, 11, 13)]
}
pe.save_book_as(
bookdict=data,
dest_chart_type='histogram',
dest_file_name='histogram.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Histogram directly
Single histogram¶
Here is the source code to draw single sheet histogram:
sheet_name = 'Wide bars'
data = [(5, 0, 10), (4, 5, 13), (2, 0, 15)]
pe.save_as(
array=data,
sheet_name=sheet_name,
dest_chart_type='histogram',
dest_file_name='single_histogram.svg',
dest_no_prefix=True
)
XY¶
BASIC¶
Basic XY Lines, drawing cosinus:
Here is the source code using pyexcel:
data = {
'x = cos(y)': [(cos(x / 10.), x / 10.) for x in range(-50, 50, 5)],
'y = cos(x)': [(x / 10., cos(x / 10.)) for x in range(-50, 50, 5)],
'x = 1': [(1, -5), (1, 5)],
'x = -1': [(-1, -5), (-1, 5)],
'y = 1': [(-5, 1), (5, 1)],
'y = -1': [(-5, -1), (5, -1)]
}
pe.save_book_as(
bookdict=data,
dest_chart_type='xy',
dest_title='XY Cosinus',
dest_file_name='xy_cosinus.svg',
dest_no_prefix=True
)
Here is the source code using pygal
Single xy line¶
Here is the source code to draw single sheet histogram:
from math import cos
sheet_name = 'x = cos(y)'
data = [(cos(x / 10.), x / 10.) for x in range(-50, 50, 5)]
pe.save_as(
array=data,
sheet_name=sheet_name,
dest_chart_type='xy',
dest_title='XY Cosinus',
dest_file_name='single_xy_cosinus.svg',
dest_no_prefix=True
)
Pie chart¶
Here is the source code using pyexcel:
title = 'Browser usage in February 2012 (in %)'
data = OrderedDict()
data['IE'] = [19.5]
data['Firefox'] = [36.6]
data['Chrome'] = [36.3]
data['Safari'] = [4.5]
data['Opera'] = [2.3]
pe.save_as(
adict=data,
dest_title=title,
dest_chart_type='pie',
dest_file_name='pie.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Pie directly
Radar chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
x_labels = [
'Richards', 'DeltaBlue', 'Crypto', 'RayTrace',
'EarleyBoyer', 'RegExp', 'Splay', 'NavierStokes']
data = {
'Chrome': [6395, 8212, 7520, 7218, 12464, 1660, 2123, 8607],
'Firefox': [7473, 8099, 11700, 2651, 6361, 1044, 3797, 9450],
'Opera': [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669],
'IE': [43, 41, 59, 79, 144, 136, 34, 102],
}
pe.save_as(
adict=data,
dest_x_labels=x_labels,
dest_title=title,
dest_chart_type='radar',
dest_file_name='radar.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Radar directly
Box chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
data = OrderedDict()
data['Chrome'] = [6395, 8212, 7520, 7218, 12464, 1660, 2123, 8607]
data['Firefox'] = [7473, 8099, 11700, 2651, 6361, 1044, 3797, 9450]
data['Opera'] = [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]
data['IE'] = [43, 41, 59, 79, 144, 136, 34, 102]
pe.save_as(
adict=data,
dest_title=title,
dest_chart_type='box',
dest_file_name='box.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Box directly
Dot chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
data = OrderedDict()
data['x labels'] = [
'Richards', 'DeltaBlue', 'Crypto',
'RayTrace', 'EarleyBoyer', 'RegExp',
'Splay', 'NavierStokes']
data['Chrome'] = [6395, 8212, 7520, 7218, 12464, 1660, 2123, 8607]
data['Firefox'] = [7473, 8099, 11700, 2651, 6361, 1044, 3797, 9450]
data['Opera'] = [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]
data['IE'] = [43, 41, 59, 79, 144, 136, 34, 102]
pe.save_as(
adict=data,
dest_title=title,
dest_chart_type='dot',
dest_file_name='dot.svg',
dest_x_label_rotation=30,
dest_no_prefix=True
)
Here is the source code using pygal.Dot directly
Funnel chart¶
Here is the source code using pyexcel:
title = 'V8 benchmark results'
data = OrderedDict()
data['x labels'] = [
'Richards', 'DeltaBlue', 'Crypto',
'RayTrace', 'EarleyBoyer', 'RegExp',
'Splay', 'NavierStokes']
data['Chrome'] = [6395, 8212, 7520, 7218, 12464, 1660, 2123, 8607]
data['Firefox'] = [7473, 8099, 11700, 2651, 6361, 1044, 3797, 9450]
data['Opera'] = [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]
pe.save_as(
adict=data,
dest_title=title,
dest_chart_type='funnel',
dest_file_name='funnel.svg',
dest_no_prefix=True
)
Here is the source code using pygal.Funnel directly