Data visualization is a scientific method of finding out the patterns, anomalies, and outliers in the data. It is a method that is used to create the graphs and plots which helps in finding out the trend in the data because it makes data simpler in terms of understanding by the human brain and we identify trends with naked eyes.
Python provides different visualization packages that help in creating different types of charts, graphs, and plots. Pygal is an open-source python library that not only creates highly interactive plots but also creates SVG images of the graphs/plots so that we can use it and customize it accordingly. Pygal is highly customizable and creates graphs with a few lines of code.
Sign up for your weekly dose of what's up in emerging technology.
Pygal creates a variety of plots like a bar, area, histogram, line, etc and due to the high scalability of the images of the plot downloaded as SVG, we will have good quality images that can be embedded into different projects, websites, etc.
In this article, we will go through different charts that we can create using pygal and also see how we can download them in the SVG format.
We will start exploring pygal but before that, we need to install pygal using pip install pygal.
- Importing required libraries
We will be importing pygal for visualization and pandas for importing the dataset for which we will be creating the visualizations.
import pandas as pd
- Loading the Dataset
We will be working with an Advertisement dataset that contains different attributes like ‘TV’, ‘Radio’, etc. and a target variable ‘Sales’.
df = pd.read_csv(‘Advertising.csv’)
- Creating Bars and Graphs
Now we will use pygal to create different bars and graphs using the dataset we have loaded. We will start by creating some basic charts and then move to some advance charts and downloading all the graphs and charts in SVG formats.
- Bar Charts
Bar charts represent the data in the form of horizontal or vertical bars with the values they represent. Pygal supports different types of Bar charts.
bar_graphs = pygal.Bar()
- Line charts
A line chart displays the data or information as a series of data points on a line.
line_chart = pygal.Line()
- Box Plots
Box Plots are considered as the statistical graphs which are used to display the numerical data with their quartile information. They are generally used to visualize the outliers in the data.
box_plot = pygal.Box()
box_plot.title = 'Advertising'
- Dot Plots
A dot plot is a statistical plot that is used to display the data in forms of the dot, the size of the dot represents the values i.e higher the value bigger is the dot.
dot_chart = pygal.Dot()
dot_chart.title = 'Advertising'
- Funnel Charts
Funnel charts are used to visualize the progressive reduction or expansion of data when it passes from different phases. It is generally used to represent the Sales data.
funnel_chart = pygal.Funnel()
funnel_chart.title = 'Advrtising'
- Gauge Chart
A gauge chart combines the doughnut chart and pie chart, it is used to visualize the data at a particular value.
gauge_chart = pygal.Gauge(human_readable=True)
gauge_chart.title = 'Advertising'
gauge_chart.range = [0, 500]
Treemaps are used to represent data in nested forms usually in rectangles shape. The size of the map resent the value i.e higher the value greater is the size of the treemap.
treemap = pygal.Treemap()
treemap.title = 'Advertisement TreeMap'
Pygal provides different types of parameters for different graphs, we can manipulate different designs, features, and render them accordingly.
In this article, we learned about Pygal, a visualization package in python which provides highly interactive and scalable visualizations. We saw how we can create different charts and plots from basic to advanced in just a few lines of code. We downloaded the images in SVG format which makes it scalable for using it in different applications or websites.