Show plots with pygal

1.1k views Asked by At

I want to try plots with pygal; however, when I do render nothing appears:

xy_chart = pygal.XY()
xy_chart.add('test', [(1,2), (2,2)])
xy_chart.render('test.svg')

Presumably, that's because the format is svg. Can I somehow save the images in standard formats or see them in python using pygal?

I tried to install dependencies for png support, but unfortunately each package requires additional installment of other packages, which eventually leads to errors.

1

There are 1 answers

0
ate50eggs On

replace the last line with this:

xy_chart.render_to_file('test.svg')

render() returns a string, but it doesn't write a file directly. Try doing this to see what I mean:

svg_content = xy_chart.render()
f = open('test.svg', 'w')
print >> f, svg_content
f.close()