A deep dive into PyeCharts, a Python tool for data visualization
In the context of analytics, data visualization is essential as it allows users or customers to visualize large amounts of data and simultaneously extract important information that can propel the business forward. When it comes to Pythonic methods, there are several to choose from, such as Matplotlib, Seaborn and others. However, there are relatively few that have an interactive plot in a pythonic approach. In this article, we’ll take a look at PyeCharts, a Python-based tool that can generate interactive plots within a few lines of code in a variety of formats. The main points covered in this article are listed below.
Contents
- About data visualization
- Python-based visualization tools
- Data visualization with PyeCharts
Let’s start the discussion by understanding what data visualization is.
Machine Learning Developers Summit 2022. Last Day To Book Early Bird Passes>>
About data visualization
The practice of placing information in a visual context, such as a map or graph, to make it easier for the human brain to absorb and extract information. The primary purpose of data visualization is to make it easier to identify patterns, trends, and outliers in a large dataset. The term is frequently used interchangeably with other terms such as information graphics, information visualization, and statistical graphics.
Data visualization is a data science technique that asserts that once data is collected, processed, and modeled, it must be seen in order to draw conclusions. Data visualization is part of a larger field called Data Presentation Architecture (DPA), which aims to find, retrieve, modify, format, and transfer data as quickly as possible.
Data visualization is required for almost any operation. Teachers can use it to display test scores, IT people can use it to improve artificial intelligence (AI), and executives can use it to share information with stakeholders. Large-scale data projects require this as well. Businesses needed a way to quickly and easily get a big picture of their data as they were accumulating large volumes of data in the early years of the big data trend.
Python-based visualization tools
In this section, we’ll go over some of the famous Python-based tools used for data visualization.
Matplotlib
Matplotlib is a Python 2D plotting and data visualization library. It is the most popular and widely used plotting library in the Python community. It comes with an interactive environment which can be used on a variety of platforms. Matplotlib is a Python library that can be used in Python scripts, Python and IPython shells, Jupyter notebooks, web application servers, etc.
Tkinter, GTK +, wxPython, Qt, and other GUI toolkits can be used to integrate plots into applications. So we can create charts, bar charts, pie charts, histograms, scatter plots, error charts, power spectra, stemplots and any other visualization chart you want with Matplotlib.
Seaborn
Seaborn is a Matplotlib-based Python data visualization framework that is closely related to NumPy and pandas data structures. Seaborn offers a number of dataset oriented plotting routines that work with data blocks and tables containing entire data sets.
Then, it performs the statistical aggregation and mapping tasks on its own to create the informative visualizations that the user wants. It is a high-level interface for creating visually appealing and useful statistical visuals, which are crucial for studying and understanding data.
plot
Plotly is a graphics library that can be used to create data visualizations for free. Plotly (plotly.py) is a web-based data visualization tool that is built on the Plotly JavaScript library (plotly.js).
It can be used to create web data visualizations that can be viewed in Jupyter notebooks or web applications using Dash or saved as individual HTML files. Point clouds, histograms, line charts, bar charts, pie charts, error bars, boxplots, multiple axes, sparklines, dendrograms, 3D charts and other types of charts are available in Plotly.
Geoplotlib
Most data visualization libraries don’t have much support for creating maps or working with geographic data, which is why Geoplotlib is such a useful Python library. It facilitates the creation of geographic maps in particular, with a variety of map types such as point density maps, choropleths and symbol maps available.
One thing to keep in mind is that installation requires NumPy and Pyglet, but that’s not a major drawback. Especially since you want to create geographic maps and Geoplotlib is the only great map creation option available.
Data visualization with PyeCharts
In this section, we will try to plot different types of charts using Pyecharts.
PyeCharts is a class library that allows you to create an Echarts chart. Echarts is an open source Baidu data visualization JS library. Echarts generates excellent graphical visual effects and Pyecharts is anchored with Python, which makes it easy to use the data generation map directly in Python.
In our Jupyter Notebook, Pyecharts works the same way we use visualization libraries in Python. PyeCharts offers a variety of configuration options, allowing you to quickly create the chart you want.
Let’s start with the library by installing it first. While I was looking for this tool, the code available in its official documentation works fine on a specific version of it. If you install directly without specifying the version, some of the plots may not be available.
All of the graphics we are going to create here will be available as HTML files in the local directory.
! pip install pyecharts==0.5.11
Please note that all the graphics we will create here will be available as HTML files in the local directory.
Bar chart
Here we are going to plot a simple multiple bar graph that shows the sales of cars from different manufacturers.
from pyecharts import Bar Bar = Bar("Months Vs Sales of Car", "Various Manufactures") Bar.add("Mahindra", ['MAY','JUNE','JUL','AUG'], [45,38,20,50], IS_MORE_UTILS = True) Bar.add("Tata", ['MAY','JUNE','JUL','AUG'], [40,48,38,50], IS_MORE_UTILS = True) Bar.add("Kia", ['MAY','JUNE','JUL','AUG'], [50,42,15,20], IS_MORE_UTILS = True) Bar.render('bar.html') # Generates a Bar.html file in the specified directory

Dynamic scatter plot
As we are very familiar with point clouds, here the dynamic point cloud is nothing but we have added additional animation with separate points with separate symbolic representation.
from pyecharts import EffectScatter es =EffectScatter("Dynamic scatter plot for random X and Y points") es.add("", [10], [18], symbol_size=20, effect_scale=3.5, effect_period=3, symbol="pin") es.add("", [20], [9], symbol_size=12, effect_scale=4.5, effect_period=4,symbol="rect") es.add("", [30], [15], symbol_size=30, effect_scale=5.5, effect_period=5,symbol="roundRect") es.add("", [40], [40], symbol_size=10, effect_scale=6.5, effect_brushtype="fill",symbol="diamond") es.add("", [50], [30], symbol_size=16, effect_scale=5.5, effect_period=3,symbol="arrow") es.add("", [60], [20], symbol_size=6, effect_scale=2.5, effect_period=3,symbol="triangle") es.render('Scatter.html')

Nested pie chart
Here we are going to plot a nested version of Pie plot which is quite simple to plot. We just need to add more labels and values using .to add method and carefully specifying the radius.
from pyecharts import Pie pie =Pie("Pie illustration example", title_pos="center", width=1000, height=600) pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148], radius=[40, 55],is_label_show=True) pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30], legend_orient="vertical", legend_pos="left") pie.render('nested pie.html')

Liquid level graph
Liquid Plot is one of those plots that I only found this frame, and to draw it very simple only takes 3 lines. The plot animation satisfies its name.
from pyecharts import Liquid liquid =Liquid("Waterlevel indication") liquid.add("Liquid", [0.7328]) liquid.render('water_ball.html')

Gauge graph
You have seen various analog counters or processing counters, PyeCharts provide it under the gauge plot as shown below.
from pyecharts import Gauge gauge = Gauge('project completion progress') gauge.add('progress table', 'completion rate' , 73.28) gauge.render('Gauge.html')

Funnel chart
A funnel chart is used to show chronological events, increasing or decreasing numbers. PyeChart example of funnel chart as shown below.
from pyecharts import Funnel Attr = ['Cognitive ',' understand ',' recognized ',' Consider ',' intention ',' purchase '] value = [120, 100, 80, 60, 40, 20] Funnel = Funnel('customer purchase analysis') Funnel.add('Cloth Purchase', Attr, value, is_label_show = True, label_pos="inside", legend_orient="vertical", legend_pos="right",label_text_color="# fff") Funnel.render('Funnel.html') # Generates files in the specified directory

Online chart
Line chart is used to display information as a series of data points connected by a line. Below is an example of a line graph.
from pyecharts import Line attr =["Shirt", "T-Shirt", "Jeans", "Kurtas", "Salvar", "Shoes"] v1 =[5, 20, 36, 10, 10, 100] v2 =[55, 60, 16, 20, 15, 80] line =Line("Pacing chart for Shop A and Shop B","X-axis-->Cloths, Y-axis-->Pricing") line.add("Shop A", attr, v1, mark_point=["average"]) line.add("Shop B", attr, v2, is_smooth=True, mark_line=["max", "average"]) line.render('poly_line.html')

Polar map
Polar maps are circular maps that display information in the form of polar coordinates using values and angles. Polar maps can be used to display scientific data. Below is an example of a polar map.
from pyecharts import Polar Radius_ =['Monday_','Tuesday_','Wednesday_','Thursday_','Friday_','Saturday_','Sunday_'] po =Polar("Polar_coordinate_system_", width=1200, height=600) po.add("A", [1, 2, 3, 4, 3, 5, 1], radius_data=Radius_, type="barRadius", is_stack=True) po.add("B", [2, 4, 6, 1, 2, 3, 1], radius_data=Radius_, type="barRadius", is_stack=True) po.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=Radius_, type="barRadius", is_stack=True) po.render('polar_test.html')

Radar map
A radar chart is a two-dimensional graphical representation of multivariate data with three or more quantitative variables represented on axes that start at the same point. Below is an example of a radar plot.
from pyecharts import Radar schema =[ ("Sales", 6500), ("management", 16000), ("information Technology", 30000), ("Customer service", 38000), ("Research and development", 52000), ("market", 25000)] v1 =[[4300, 10000, 28000, 35000, 50000, 19000]] v2 =[[5000, 14000, 28000, 31000, 42000, 21000]] radar =Radar() radar.config(schema) radar.add("Budget allocation", v1, is_splitline=True, is_axisline_show=True) radar.add("Actual overhead", v2, label_color=["#4e79a7"], is_area_show=False) radar.render('rader_test.html')

Final words
Through this article, we have seen what data visualization is and its importance. Later we saw some of the widely used Python-based visualization tools. Finally, we practically saw the PyeCharts package in Python. Charts built using these packages are dynamic, so numbers appear with a transparent background whenever the mouse is over them. The graphics built here are very attractive. To create nice graphics, less code is required when using this package. There is also support for the Creative Theme Palette with PyeCharts.
Comments are closed.