|
Revision 169, 1.7 kB
(checked in by lgs, 3 years ago)
|
|
Big refactor about how the colors scheme are created and used. See #29
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | import random |
|---|
| 19 | import sys |
|---|
| 20 | |
|---|
| 21 | import cairo |
|---|
| 22 | |
|---|
| 23 | import pycha.scatter |
|---|
| 24 | |
|---|
| 25 | def scatterplotChart(output): |
|---|
| 26 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200) |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | dataSet = ( |
|---|
| 30 | ('points', [(i, random.random() * 100.0) for i in range(100)]), |
|---|
| 31 | ) |
|---|
| 32 | |
|---|
| 33 | options = { |
|---|
| 34 | 'background': { |
|---|
| 35 | 'color': '#eeeeff', |
|---|
| 36 | 'lineColor': '#444444' |
|---|
| 37 | }, |
|---|
| 38 | 'colorScheme': { |
|---|
| 39 | 'name': 'gradient', |
|---|
| 40 | 'args': { |
|---|
| 41 | 'initialColor': 'blue', |
|---|
| 42 | }, |
|---|
| 43 | }, |
|---|
| 44 | 'legend': { |
|---|
| 45 | 'hide': True, |
|---|
| 46 | }, |
|---|
| 47 | 'padding': { |
|---|
| 48 | 'left': 55 |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | chart = pycha.scatter.ScatterplotChart(surface, options) |
|---|
| 52 | |
|---|
| 53 | chart.addDataset(dataSet) |
|---|
| 54 | chart.render() |
|---|
| 55 | |
|---|
| 56 | surface.write_to_png(output) |
|---|
| 57 | |
|---|
| 58 | if __name__ == '__main__': |
|---|
| 59 | if len(sys.argv) > 1: |
|---|
| 60 | output = sys.argv[1] |
|---|
| 61 | else: |
|---|
| 62 | output = 'scatterchart.png' |
|---|
| 63 | scatterplotChart(output) |
|---|