This is an introduction to the python drawing package pygal. Since this is just an introduction, I will not touch on detailed grammar in this article.
The install method is possible with pip install as follows.
pip install pygal
First of all, you can write a bar graph by writing like this. (Somehow it's similar to keras)
import pygal #import pygal
bar_chart = pygal.Bar() #Create a bar chart object
bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) #Put a value in the object
bar_chart.render_to_file('bar_chart.svg') #Save the created graph as an svg file
When executed, bar_chart.svg
will be created in the current directory, so if you open this with a browser, this figure will be displayed.
Interactive diagrams are drawn, such as plotly.
Alternatively, install the lxml package and
If you rewrite the part to bar_chart.render_to_file ('hoge.svg')
or bar_chart.render ()
to bar_chart.render_in_browser ()
from render
You can check with the browser quickly.
Alternatively, for those who mainly analyze with notebook, you can embed the graph in notebook by writing as follows.
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>
"""
display(HTML(base_html.format(rendered_chart=bar_chart.render(is_unicode=True))))
pygal creates SVG. SVG can be edited in any editor and displayed in very high quality resolution. SVG can also be easily integrated with Flask and Django.
In addition to bar graphs, you can draw various graphs such as the following. (The graph is borrowed from the document) It supports everything from graphs that are often used in analysis to drawing on maps.
Please use it ~
Recommended Posts