def plot(self): g = Plot( dict( width=640, height=480, graph_title="Plot", show_graph_title=True, no_css=True, key=True, scale_x_integers=True, scale_y_integers=True, min_x_value=0, min_y_value=0, show_data_labels=True, show_x_guidelines=True, show_x_title=True, x_title="Time", show_y_title=True, y_title="Ice Cream Cones", y_title_text_direction='bt', )) # add a few random datasets for n in range(1, 4): g.add_data( dict(data=flatten(get_data_set()), title='series %d' % n)) res = XML(g.burn()) return render(chart=res)
def test_pairs(self): """ Test that it is acceptable to use pairs for data. """ g = Plot(dict(show_data_points=True)) g.add_data(dict(data=[(1, 0), (2, 1)], title='pairs')) assert 'circle' in g.burn()
def test_pairs(self): """ Test that it is acceptable to use pairs for data. """ g = Plot(dict(show_data_points=True)) g.add_data(dict(data=[(1, 0), (2, 1)], title='pairs')) assert b'circle' in g.burn()
def plot(self): g = Plot(dict( width = 640, height = 480, graph_title = "Plot", show_graph_title = True, no_css = True, key = True, scale_x_integers = True, scale_y_integers = True, min_x_value = 0, min_y_value = 0, show_data_labels = True, show_x_guidelines = True, show_x_title = True, x_title = "Time", show_y_title = True, y_title = "Ice Cream Cones", y_title_text_direction = 'bt', )) # add a few random datasets for n in range(1, 4): g.add_data(dict( data = flatten(get_data_set()), title = 'series %d' % n, )) res = XML(g.burn()) return render(chart=res)
def sample_PlotTextLabels(): g = Plot( { 'draw_lines_between_points': False, 'min_x_value': 0, 'min_y_value': 0, 'show_x_guidelines': True, } ) # Processed Apple production 2015 # Any object with a .text attribute will do; # we like namedtuple(). from collections import namedtuple Datum = namedtuple("Datum", "x y text") g.add_data( { 'data': [ Datum(8.24, 80.85, 'ES'), Datum(0.17, 6.73, 'IE'), Datum(0, 0, 'IS'), ], 'title': 'Processed Apple', } ) return g
def sample_PlotTextLabels(): g = Plot({ 'draw_lines_between_points': False, 'min_x_value': 0, 'min_y_value': 0, 'show_x_guidelines': True }) # Processed Apple production 2015 # Any object with a .text attribute will do; # we like namedtuple(). from collections import namedtuple Datum = namedtuple("Datum", "x y text") g.add_data({ 'data': [ Datum(8.24, 80.85, 'ES'), Datum(0.17, 6.73, 'IE'), Datum(0, 0, 'IS'), ], 'title': 'Processed Apple' }) return g
def test_python3_show_points(self): """ Test that show_data_points creates circle elements in output. """ g = Plot(dict(show_data_points=True)) g.add_data(dict(data=[1, 0, 2, 1], title='foo')) assert 'circle' in g.burn()
def test_python3_show_points(self): """ Test that show_data_points creates circle elements in output. """ g = Plot(dict(show_data_points=True)) g.add_data(dict(data=[1, 0, 2, 1], title='foo')) assert b'circle' in g.burn()
def test_iterable_data_flat(self): g = Plot() spec = dict( data=flatten(self.get_data()), title='labels', ) g.add_data(spec) svg = g.burn() assert b'text="(1.00, 0.00)"' in svg
def test_iterable_data_grouped(self): g = Plot() spec = dict( data=self.get_data(), title='labels', ) g.add_data(spec) svg = g.burn() assert b'text="(1.00, 0.00)"' in svg
def test_all_y_values_zero(self): """ If all y values are zero, the graph should render without error. """ g = Plot() pairs = [0, 0.0] spec = dict(data=pairs, title='test') g.add_data(spec) g.burn()
def test_iterable_data_flat(self): g = Plot() spec = dict( data=flatten(self.get_data()), title='labels', ) g.add_data(spec) svg = g.burn() assert 'text="(1.00, 0.00)"' in svg
def test_index_error_2010_04(self): """ Reported by Jean Schurger a 'IndexError: tuple index out of range' when there are only two values returned by float_range (in the case there are only two different 'y' values in the data) and 'scale_y_integers == True'. Credit to Jean for the test code as well. """ g = Plot(dict(scale_y_integers = True)) g.add_data(dict(data=[1, 0, 2, 1], title='foo')) g.burn()
def test_text(self): """ Test that data with .text attributes make text labels. """ from collections import namedtuple D = namedtuple("D", 'x y text') g = Plot(dict(show_data_values=True)) g.add_data(dict(data=[D(1, 0, 'Sam'), D(2, 1, 'Dan')], title='labels')) svg = g.burn() assert 'Sam' in svg assert 'Dan' in svg
def sample_Plot(): g = Plot( { 'min_x_value': 0, 'min_y_value': 0, 'area_fill': True, 'stagger_x_labels': True, 'stagger_y_labels': True, 'show_x_guidelines': True, } ) 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': [[0.5, 35], [1, 20], [3, 10.5]], 'title': 'series 3'}) return g
def performance_plot(): g = Plot({ 'min_x_value': 0, 'min_y_value': 0, 'area_fill': True, 'stagger_x_labels': True, 'stagger_y_labels': True, 'show_x_guidelines': True })
def test_rounding(self): """ Labels should be rounded to 4 digits of precision. """ g = Plot({ 'show_data_values': False, 'show_data_points': False, 'min_x_value': 0, 'max_x_value': 0.5, 'min_y_value': 0, 'max_y_value': 1, 'scale_y_divisions': 0.1, 'scale_x_divisions': 0.1, 'area_fill': False, 'show_x_guidelines': True, 'show_y_guidelines': True, }) g.add_data({'data': self.read_data('source.csv'), 'title': 'title'}) res = g.burn() assert '0.30' not in res assert '0.3' in res pathlib.Path('test.svg').write_text(res)
def sample_Plot(): g = Plot({ 'min_x_value': 0, 'min_y_value': 0, 'area_fill': True, 'stagger_x_labels': True, 'stagger_y_labels': True, 'show_x_guidelines': True }) 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'}) return g
def test_inline_styles(self): g = Plot(dict(css_inline=True)) g.add_data(dict(data=[1, 0, 2, 1], title='foo')) g.burn()
def test_iterable_data_grouped(self): g = Plot() spec = dict(data=self.get_data(), title='labels') g.add_data(spec) svg = g.burn() assert 'text="(1.00, 0.00)"' in svg
import sys, os from svg.charts.plot import Plot g = Plot({ 'min_x_value': 0, 'min_y_value': 0, 'area_fill': True, 'stagger_x_labels': True, 'stagger_y_labels': True, 'show_x_guidelines': True }) 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'}) res = g.burn() f = open(r'Plot.py.svg', 'w') f.write(res) f.close() from svg.charts import time_series g = time_series.Plot({}) g.timescale_divisions = '4 hours' g.stagger_x_labels = True g.x_label_format = '%d-%b %H:%M' #g.max_y_value = 200 g.add_data({'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21], 'title': 'series 1'}) res = g.burn()