Introduction of python drawing package pygal

Overview

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.

Introduction of pygal

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.

スクリーンショット 2020-02-23 19.16.07.png

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.

スクリーンショット 2020-02-23 19.38.37.png スクリーンショット 2020-02-23 19.38.46.png スクリーンショット 2020-02-23 19.38.57.png スクリーンショット 2020-02-23 19.39.10.png スクリーンショット 2020-02-23 19.39.26.png スクリーンショット 2020-02-23 19.39.38.png スクリーンショット 2020-02-23 19.39.54.png スクリーンショット 2020-02-23 19.40.09.png スクリーンショット 2020-02-23 19.40.45.png

Please use it ~

reference

Recommended Posts

Introduction of python drawing package pygal
Introduction of Python
Introduction of Python
Introduction of activities applying Python
A record of patching a python package
Introduction of ferenOS 3 (package update, installation)
Record of Python introduction for newcomers
General Theory of Relativity in Python: Introduction
Easy introduction of speech recognition with Python
Drawing with Matrix-Reinventor of Python Image Processing-
Easy introduction of python3 series and OpenCV3
[Introduction to Data Scientists] Basics of Python ♬
[python] Streamline drawing
Introduction of scikit-optimize
Introduction of PyGMT
Basics of Python ①
Basics of python ①
Copy of python
Introduction of cymel
[Introduction to Udemy Python 3 + Application] 26. Copy of dictionary
Python & Machine Learning Study Memo ②: Introduction of Library
Introduction of Python Imaging Library (PIL) using HomeBrew
Kyoto University Python Lecture Material: Introduction of Columns
[Introduction to Python] Basic usage of lambda expressions
Flow of creating your own package with setup.py with python
[Python] Operation of enumerate
List of python modules
Introduction of trac (Windows + trac 1.0.10)
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
Unification of Python environment
Introduction of ferenOS 1 (installation)
Python package development notes
[python] behavior of argmax
Python test package memo
Graph drawing in python
[Chapter 5] Introduction to Python with 100 knocks of language processing
Usage of Python locals ()
Introduction of Virtualenv wrapper
Introduction to Python language
Python ipaddress package notes
Note when putting lxml of python package in ubuntu 14.04
Introduction to OpenCV (python)-(2)
Installation of Python 3.3 rc1
[Introduction to Udemy Python3 + Application] 53. Dictionary of keyword arguments
Python Basic Course (Introduction)
[Chapter 3] Introduction to Python with 100 knocks of language processing
# 4 [python] Basics of functions
[Chapter 2] Introduction to Python with 100 knocks of language processing
Basic knowledge of Python
Drawing with Python Tinker
Summary of Python arguments
Python package manager comparison
Python Beginner's Guide (Introduction)
[Introduction to Python] Basic usage of the library matplotlib
[Introduction to Udemy Python3 + Application] 52. Tupleization of positional arguments
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Explanation of NoReverseMatch error in "python django super introduction"
python> Link> PyUserInput package |
Various processing of Python