グラフ作成

2014/12/21

Python2.7.6, XlsxWriter 0.6.4

とりあえず、公式サンプルそのまま引用

import xlsxwriter 

workbook = xlsxwriter.Workbook('chart.xlsx') 
worksheet = workbook.add_worksheet() 

# Create a new Chart object. 
chart = workbook.add_chart({'type': 'column'}) 

# Write some data to add to plot on the chart. 
data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] 
worksheet.write_column('A1', data[0]) 
worksheet.write_column('B1', data[1]) 
worksheet.write_column('C1', data[2]) 

# Configure the chart. In simplest case we add one or more data series. 
chart.add_series({'values': '=Sheet1!$A$1:$A$5'}) 
chart.add_series({'values': '=Sheet1!$B$1:$B$5'}) 
chart.add_series({'values': '=Sheet1!$C$1:$C$5'}) 

# Insert the chart into the worksheet. 
worksheet.insert_chart('A7', chart) 
workbook.close()

The Chart Class
https://xlsxwriter.readthedocs.org/chart.html

typeは以下

type 種類
area 面グラフ
bar 横棒グラフ
column 縦棒グラフ
line 線グラフ
pie 円グラフ
doughnut ドーナツグラフ
scatter 散布図
stock 株価チャート
radar レーダー図

ものによって以下のsubtypeがある

area
    stacked
    percent_stacked
bar
    stacked
    percent_stacked
column
    stacked
    percent_stacked 
scatter 
    straight_with_markers 
    straight 
    smooth_with_markers 
    smooth 
radar 
    with_markers 
    filled

Chart Examples
http://xlsxwriter.readthedocs.org/en/latest/chart_examples.html