In the world of analytics, data visualization plays a crucial role. It enables users and clients to comprehend and extract meaningful insights from vast amounts of data, thereby propelling businesses forward. When it comes to Pythonic methods, there are several options available, such as Matplotlib, Seaborn, and others. However, only a few offer an interactive plot in a pythonic approach. In this article, we will explore PyeCharts, a Python-based tool that can generate interactive plots with just a few lines of code, supporting various formats. Let’s delve into the world of data visualization and understand its significance.
About Data Visualization
Data visualization involves presenting information in a visual context, such as maps or graphs, to facilitate easier absorption and extraction of insights by the human brain. The primary purpose of data visualization is to identify patterns, trends, and outliers in large datasets. It is often used interchangeably with terms like information graphics, information visualization, and statistical graphics.
Data visualization is an essential technique in data science. After data is collected, processed, and modeled, it needs to be visualized to draw meaningful conclusions. Data visualization is a part of the broader field of data presentation architecture (DPA), which aims to find, retrieve, alter, format, and transfer data as quickly as possible.
Data visualization is indispensable across various domains. Teachers use it to display test results, computer scientists rely on it to enhance artificial intelligence (AI), and executives utilize it to share information with stakeholders. Moreover, large-scale data projects heavily rely on data visualization. As businesses accumulate vast volumes of data during the big data trend, they require a quick and easy way to gain an overview of their data.
Python-based Tools for Visualization
Now let’s explore some of the famous Python-based tools used for data visualization.
Matplotlib
Matplotlib is the most popular and widely used plotting library in the Python community. It provides a comprehensive set of tools for creating 2-D plots and visualizations. Matplotlib offers an interactive environment that can be used across various platforms. It can be utilized in Python scripts, the Python and IPython shells, Jupyter notebooks, web application servers, and more. Additionally, Matplotlib can be integrated with GUI toolkits like Tkinter, GTK+, wxPython, and Qt to embed plots into applications. With Matplotlib, you can create a wide range of visualizations, including bar charts, pie charts, histograms, scatter plots, and more.
Seaborn
Seaborn is a Python data visualization framework built on top of Matplotlib. It tightly integrates with NumPy and pandas data structures. Seaborn provides a high-level interface for creating visually appealing and informative statistical visuals. It offers dataset-oriented plotting routines that work seamlessly with data frames and arrays containing complete datasets. Seaborn automates the necessary statistical aggregation and mapping tasks, enabling users to build informative visualizations effortlessly.
Plotly
Plotly is a powerful graphing library that allows you to create data visualizations for free. It consists of two main components: Plotly.py, a Python library, and Plotly.js, a JavaScript library. Plotly.py is a web-based data visualization tool that can be used to create interactive visualizations displayed in Jupyter notebooks or web applications using Dash. It supports various chart types, including scatter plots, histograms, line charts, bar charts, pie charts, and more. Plotly is an excellent choice for creating dynamic and interactive visualizations.
Geoplotlib
Geoplotlib is a Python library specifically designed for working with geographic data and creating maps. While many data visualization libraries have limited support for geographical maps, Geoplotlib stands out by providing a wide range of map types, such as dot-density maps, choropleths, and symbol maps. It simplifies the process of creating geographical maps and is a valuable tool for any data visualization project involving geographic data.
Data Visualization with PyeCharts
Now let’s focus on PyeCharts, a Python-based library that allows you to create interactive charts using Echarts, an open-source data visualization JavaScript library developed by Baidu. PyeCharts provides seamless integration with Python, enabling you to leverage its data generation capabilities directly in Python.
Using PyeCharts is similar to working with other visualization libraries in Python. It offers a variety of configuration options, allowing you to create customized charts with ease. However, it’s important to note that while installing PyeCharts, specifying the correct version is crucial to ensure compatibility and access to all available plots.
Throughout this article, we will showcase different types of charts that can be created using PyeCharts. Each chart generated will be saved as an HTML file in the local directory, providing an interactive viewing experience.
Let’s explore some examples of charts that can be created with PyeCharts:
Bar Chart
The bar chart is a classic visualization that displays categorical data as rectangular bars. Here, we will plot a simple multibar chart showing the sales of cars across various manufacturers. The chart will visualize the sales data for different months.
from pyecharts import Bar
bar = Bar("Months Vs Sales of Car", "Various Manufacturers")
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')
Dynamic Scatter Chart
A dynamic scatter chart adds animation and distinct symbolic representations to scatter plots. It enhances the visual experience by highlighting different data points using unique animations.
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="
Dynamic Scatter Chart
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
A nested pie chart is a variation of a pie chart that displays hierarchical data. It visualizes data in concentric circles, with each ring representing a different category. Here, we will plot a nested pie chart by adding further labels and values.
from pyecharts import Pie
pie = Pie("Nested Pie Chart", 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 Chart
The liquid level chart is a unique visualization that represents data as a liquid filling a container. It is an excellent choice for visualizing ratios or progress. Creating a liquid level chart with PyeCharts is simple and requires only a few lines of code.
from pyecharts import Liquid
liquid = Liquid("Water Level Indication")
liquid.add("Liquid", [0.7328])
liquid.render('liquid_chart.html')
Gauge Chart
A gauge chart, also known as a dial or speedometer chart, represents a single value within a specific range. It is often used to display progress or metrics. With PyeCharts, you can create gauge charts with ease.
from pyecharts import Gauge
gauge = Gauge('Project Completion Progress')
gauge.add('Progress', 'Completion Rate', 73.28)
gauge.render('gauge_chart.html')
Funnel Chart
A funnel chart visualizes a process or flow where the data progressively narrows down from one stage to another. It is commonly used to analyze customer behavior or sales pipelines. Creating a funnel chart with PyeCharts is straightforward.
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_chart.html')
Line Chart
The line chart displays data points connected by lines, which helps visualize trends and patterns over time or across categories. PyeCharts provides easy-to-use tools for creating line charts.
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("Pricing 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('line_chart.html')
Polar Chart
The polar chart represents data in a circular format using polar coordinates. It is often used to visualize scientific data. With PyeCharts, creating a polar chart is simple and effective.
from pyecharts import Polar
radius = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
polar = Polar("Polar Coordinate System", width=1200, height=600)
polar.add("A", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barRadius', is_stack=True)
polar.add("B", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barRadius', is_stack=True)
polar.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barRadius', is_stack=True)
polar.render('polar_chart.html')
Radar Chart
The radar chart, also known as a spider chart, displays multivariate data using a two-dimensional graphical representation. It is particularly useful for comparing multiple quantitative variables. PyeCharts provides a straightforward approach to creating radar charts.
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('radar_chart.html')
In conclusion, we have explored the concept of data visualization and its importance in gaining insights and driving business growth. We have also discussed some popular Python-based tools for data visualization, such as Matplotlib, Seaborn, and Plotly. Additionally, we have explored PyeCharts, a powerful Python library for creating interactive charts. By leveraging the capabilities of these tools, you can create visually appealing and informative visualizations that enhance data analysis and communication.
Leave a Reply