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
Browser usage in February 2012 (in %) 19.5 283.114871902 105.730281351 36.6 290.681741008 222.119671947 36.3 164.453391678 167.713973194 4.5 218.24103439 94.949204806 2.3 234.130962219 92.0492686777 Browser usage in February 2012 (in %) IE Firefox Chrome Safari Opera 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 )
Box chart
Here is the source code using pyexcel:
V8 benchmark results 0 0 1000 1000 2000 2000 3000 3000 4000 4000 5000 5000 6000 6000 7000 7000 8000 8000 9000 9000 10000 10000 11000 11000 12000 12000 Min: 1660
Q1 : 4259
Q2 : 7369
Q3 : 8409.5
Max: 12464 61.2346153846 151.532360892 Min: 1044
Q1 : 3224
Q2 : 6917
Q3 : 8774.5
Max: 11700 166.811538462 164.425925126 Min: 34
Q1 : 42
Q2 : 69
Q3 : 119
Max: 144 272.388461538 325.474375432 Min: 1828
Q1 : 3202.5
Q2 : 4436
Q3 : 5519.5
Max: 9013 377.965384615 203.90280315 V8 benchmark results Chrome Firefox IE Opera title = 'V8 benchmark results'
sheet = pyexcel . get_sheet ( file_name = 'box.csv' )
svg = sheet . plot ( chart_type = 'box' ,
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:
Browser usage evolution (in %) 0 0 10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 Browser usage evolution (in %) 0 8.79230769231 307.961538462 2002 3.9 52.7538461538 294.237762238 2003 10.8 96.7153846154 269.957235073 2004 23.8 140.676923077 224.211314327 2005 35.3 184.638461538 183.743769051 2006 0 8.79230769231 307.961538462 2002 16.6 52.7538461538 249.547516586 2003 25 96.7153846154 219.98861395 2004 31 140.676923077 198.875112067 2005 36.4 184.638461538 179.872960373 2006 45.5 228.6 147.850815851 2007 46.3 272.561538462 145.035682266 2008 42.8 316.523076923 157.351891698 2009 37.1 360.484615385 177.409718487 2010 85.8 8.79230769231 6.03846153846 2002 84.6 52.7538461538 10.261161915 2003 84.7 96.7153846154 9.90927021696 2004 74.5 140.676923077 45.8022234176 2005 66 184.638461538 75.7130177515 2006 58.6 228.6 101.753003407 2007 54.7 272.561538462 115.476779631 2008 44.8 316.523076923 150.314057737 2009 36.2 360.484615385 180.576743769 2010 26.6 404.446153846 214.358346781 2011 20.1 448.407692308 237.231307154 2012 14.2 8.79230769231 257.992917339 2002 15.4 52.7538461538 253.770216963 2003 15.3 96.7153846154 254.122108661 2004 8.9 140.676923077 276.643177335 2005 9 184.638461538 276.291285637 2006 10.4 228.6 271.364801865 2007 8.9 272.561538462 276.643177335 2008 5.8 316.523076923 287.551819975 2009 6.7 360.484615385 284.384794692 2010 6.8 404.446153846 284.032902994 2011 7.5 448.407692308 281.569661108 2012 Chrome Firefox IE Others 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:
V8 benchmark results Chrome 3.5 Firefox 2.5 IE 1.5 Opera 0.5 Richards DeltaBl… DeltaBlue Crypto RayTrace EarleyB… EarleyBoyer RegExp Splay NavierS… NavierStokes 6395 33.8884615385 43.7788461538 Richards 8212 85.2346153846 43.7788461538 DeltaBlue 7520 136.580769231 43.7788461538 Crypto 7218 187.926923077 43.7788461538 RayTrace 12464 239.273076923 43.7788461538 EarleyBoyer 1660 290.619230769 43.7788461538 RegExp 2123 341.965384615 43.7788461538 Splay 8607 393.311538462 43.7788461538 NavierStokes 7473 33.8884615385 119.259615385 Richards 8099 85.2346153846 119.259615385 DeltaBlue 11700 136.580769231 119.259615385 Crypto 2651 187.926923077 119.259615385 RayTrace 6361 239.273076923 119.259615385 EarleyBoyer 1044 290.619230769 119.259615385 RegExp 3797 341.965384615 119.259615385 Splay 9450 393.311538462 119.259615385 NavierStokes 43 33.8884615385 194.740384615 Richards 41 85.2346153846 194.740384615 DeltaBlue 59 136.580769231 194.740384615 Crypto 79 187.926923077 194.740384615 RayTrace 144 239.273076923 194.740384615 EarleyBoyer 136 290.619230769 194.740384615 RegExp 34 341.965384615 194.740384615 Splay 102 393.311538462 194.740384615 NavierStokes 3472 33.8884615385 270.221153846 Richards 2933 85.2346153846 270.221153846 DeltaBlue 4203 136.580769231 270.221153846 Crypto 5229 187.926923077 270.221153846 RayTrace 5810 239.273076923 270.221153846 EarleyBoyer 1828 290.619230769 270.221153846 RegExp 9013 341.965384615 270.221153846 Splay 4669 393.311538462 270.221153846 NavierStokes V8 benchmark results Chrome Firefox IE Opera 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:
V8 benchmark results -50000 -50000 -40000 -40000 -30000 -30000 -20000 -20000 -10000 -10000 0 0 10000 10000 20000 20000 30000 30000 40000 40000 50000 50000 Richards DeltaBlue Crypto 6395 77.7538461538 190.287354862 Richards 8212 77.7538461538 180.116063914 Richards 7520 77.7538461538 169.161401821 Richards 7218 77.7538461538 158.898891656 Richards 12464 77.7538461538 145.193726431 Richards 1660 77.7538461538 135.358762828 Richards 2123 77.7538461538 132.724546791 Richards 8607 77.7538461538 125.252926892 Richards 7473 216.6 220.300566502 DeltaBlue 8099 216.6 199.286026247 DeltaBlue 11700 216.6 174.54472833 DeltaBlue 2651 216.6 154.289187673 DeltaBlue 6361 216.6 134.308697329 DeltaBlue 1044 216.6 119.317410767 DeltaBlue 3797 216.6 113.312261651 DeltaBlue 9450 216.6 96.6163594773 DeltaBlue 3472 355.446153846 210.469084549 Crypto 2933 355.446153846 195.165842188 Crypto 4203 355.446153846 176.41019615 Crypto 5229 355.446153846 159.849381978 Crypto 5810 355.446153846 145.887271018 Crypto 1828 355.446153846 135.412380231 Crypto 9013 355.446153846 124.492534634 Crypto 4669 355.446153846 105.741066575 Crypto V8 benchmark results Chrome Firefox Opera 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 )
Radar chart
Here is the source code using pyexcel:
V8 benchmark results 12000 12000 10000 10000 8000 8000 6000 6000 4000 4000 2000 2000 0 0 Richards 1.570796327 DeltaBlue 2.35619449 Crypto 3.141592654 RayTrace 3.926990817 EarleyBoyer 4.71238898 RegExp 5.497787144 Splay 6.283185307 NavierStokes 7.068583471 V8 benchmark results 6395 219.6 82.4137100033 Richards 8212 124.870535378 89.2744720146 DeltaBlue 7520 96.9213521609 157.0 Crypto 7218 136.336814949 216.527869094 RayTrace 12464 219.6 302.37037037 EarleyBoyer 1660 238.748917593 170.690255292 RegExp 2123 254.233878905 157.0 Splay 8607 318.885984169 86.0168510265 NavierStokes 7473 219.6 69.8407591642 Richards 8099 126.174046034 90.2063990314 DeltaBlue 11700 28.7302952503 157.0 Crypto 2651 189.019409314 178.863172758 RayTrace 6361 219.6 231.189740527 EarleyBoyer 1044 231.643054197 165.610015979 RegExp 3797 281.542928969 157.0 Splay 9450 328.610404369 79.0645105379 NavierStokes 43 219.6 156.498481553 Richards 41 219.127044806 156.661867189 DeltaBlue 59 218.637494651 157.0 Crypto 79 218.68869609 157.651524198 RayTrace 144 219.6 158.679503637 EarleyBoyer 136 221.168826984 158.121611277 RegExp 34 220.154664099 157.0 Splay 102 220.776620238 156.158791542 NavierStokes 3472 219.6 116.505301193 Richards 2933 185.766400422 132.811133271 DeltaBlue 4203 151.03372914 157.0 Crypto 5229 159.280909583 200.124304169 RayTrace 5810 219.6 224.763306471 EarleyBoyer 1828 240.686880337 172.075775104 RegExp 9013 366.634927257 157.0 Splay 4669 273.459214603 118.494095207 NavierStokes Chrome Firefox IE Opera title = 'V8 benchmark results'
sheet = pyexcel . get_sheet ( file_name = 'radar.csv' )
svg = sheet . plot ( chart_type = 'radar' ,
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:
pyexcel chart rendered by pygal 0 0 1 1 2 2 3 3 4 4 5 5 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 5: 0 133.179487179 157.0 4: 5 233.692307692 187.192307692 2: 0 196.0 247.576923077 pyexcel chart rendered by pygal histogram_wide… histogram_wide_bars.csv 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
pyexcel chart rendered by pygal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 10: 1 48.8769230769 182.16025641 12: 4 123.55 157.0 8: 11 333.992307692 207.320512821 5: 0 143.915384615 245.060897436 4: 5 252.530769231 257.641025641 2: 0 211.8 282.801282051 pyexcel chart rendered by pygal Narrow bars Wide bars 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
pyexcel chart rendered by pygal -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 pyexcel chart rendered by pygal -1: -5 174.461538462 307.961538462 -1: 5 174.461538462 6.03846153846 1: -5 257.538461538 307.961538462 1: 5 257.538461538 6.03846153846 0.2836621855: -5 227.782890781 307.961538462 -0.2107957994: -4.5 207.243866793 292.865384615 -0.6536436209: -4 188.848649595 277.769230769 -0.9364566873: -3.5 177.101029913 262.673076923 -0.9899924966: -3 174.877234757 247.576923077 -0.8011436155: -2.5 182.721726739 232.480769231 -0.4161468365: -2 198.713900636 217.384615385 0.07073720167: -1.5 218.938314531 202.288461538 0.5403023059: -1 238.443326551 187.192307692 0.8775825619: -0.5 252.453429494 172.096153846 1: 0 257.538461538 157.0 0.8775825619: 0.5 252.453429494 141.903846154 0.5403023059: 1 238.443326551 126.807692308 0.07073720167: 1.5 218.938314531 111.711538462 -0.4161468365: 2 198.713900636 96.6153846154 -0.8011436155: 2.5 182.721726739 81.5192307692 -0.9899924966: 3 174.877234757 66.4230769231 -0.9364566873: 3.5 177.101029913 51.3269230769 -0.6536436209: 4 188.848649595 36.2307692308 -0.2107957994: 4.5 207.243866793 21.1346153846 -5: -1 8.30769230769 187.192307692 5: -1 423.692307692 187.192307692 -5: 1 8.30769230769 126.807692308 5: 1 423.692307692 126.807692308 -5: 0.2836621855 8.30769230769 148.435584016 -4.5: -0.2107957994 29.0769230769 163.364411637 -4: -0.6536436209 49.8461538462 176.735009322 -3.5: -0.9364566873 70.6153846154 185.273788443 -3: -0.9899924966 91.3846153846 186.89015807 -2.5: -0.8011436155 112.153846154 181.188374546 -2: -0.4161468365 132.923076923 169.564433334 -1.5: 0.07073720167 153.692307692 154.864280642 -1: 0.5403023059 174.461538462 140.687026534 -0.5: 0.8775825619 195.230769231 130.503757266 0: 1 216.0 126.807692308 0.5: 0.8775825619 236.769230769 130.503757266 1: 0.5403023059 257.538461538 140.687026534 1.5: 0.07073720167 278.307692308 154.864280642 2: -0.4161468365 299.076923077 169.564433334 2.5: -0.8011436155 319.846153846 181.188374546 3: -0.9899924966 340.615384615 186.89015807 3.5: -0.9364566873 361.384615385 185.273788443 4: -0.6536436209 382.153846154 176.735009322 4.5: -0.2107957994 402.923076923 163.364411637 x = -1 x = 1 x = cos(y) y = -1 y = 1 y = cos(x) book = pyexcel . get_book ( file_name = 'xy.xlsx' )
svg = book . plot ( chart_type = 'xy' ,
width = 600 , height = 400 , explicit_size = True )