Skip to content

Instantly share code, notes, and snippets.

@attomos
Created December 30, 2017 03:48
Show Gist options
  • Select an option

  • Save attomos/967851247c63735ff18c1383888c3a78 to your computer and use it in GitHub Desktop.

Select an option

Save attomos/967851247c63735ff18c1383888c3a78 to your computer and use it in GitHub Desktop.
Render Pygal SVG on Jupyter https://stackoverflow.com/a/45813876/606355
import pygal
from IPython.display import display, HTML
base_html = """
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
<script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
</head>
<body>
<figure>
{rendered_chart}
</figure>
</body>
</html>
"""
def galplot(chart):
rendered_chart = chart.render(is_unicode=True)
plot_html = base_html.format(rendered_chart=rendered_chart)
display(HTML(plot_html))
bar_chart = pygal.StackedBar()
bar_chart.add('Bars', [1,2,3,4,5])
galplot(bar_chart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment