PyeChart Data Visualization Library for Enhanced Visuals
If you want to make charts like the above one so let’s get to know about the amazing Pyecharts library. Generally, the bar chart which we use of matplotlib library is static and there are very few parameters to tweak to make it more appealing to the audience but if I say with less line of code we can create eye-pleasing charts. Yes!!!!!! so let’s see how it is done.
The Pyecharts library uses Echarts to generate charts. Pyecharts library provides the interface between Python and Echarts. The Pyecharts work usually like we use visualization library in Python or R in our Jupyter Notebook. Pyecharts have flexible configuration options, so you can easily match the desired chart you want to make. Detailed documentation and samples to help developers get started the faster project
This Pyecharts library supports the chained calls and we can easily integrate them into Flask, Django Web framework, and other mainstream. Let’s look at some examples, and many more can be found at Pyecharts Gallery!
Installing the Pyechart library, with the pip command
pip install pyecharts==1.7.1
from pyecharts import options as opts from pyecharts.charts import Liquid from pyecharts.globals import SymbolType from pyecharts.charts import Bar, Line
Parameters for the chart
How to create a pyechart chart? Let’s see the parameters to make an interactive chart.
- For showing data on the x-axis: add_xaxis()
- For showing data on the y-axis: add_yaxis()
- set_global_ops gives a lot of room where we can have the title and subtitle to the chart.
- render() create a file named render.html in the root directory defaultly, which supports path parameter and set the location the file save in, for instance, render(r”e:my_first_chart.html”), open file with your browser.
- In order to have toolbox buttons on the chart, you just need to give a bit more configuration. Then you can click the image download button.
- init_opts helps to set the various theme palate.
Benefits of PyeChart
- The pyechart data is a dynamic chart and whenever the mouse is hovering on the chart, the number shows up with the transparent background. The charts are very eye-catching. Less code is needed to make pleasant charts.
- The library does provide 3D visuals which are great
- Creative theme palate
Color palate example. Let’s first see the dark mode palate for the bar chart.
from pyecharts.charts import Bar bar = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK)) .add_xaxis(['JAN','FEB','MAR','APR']) .add_yaxis('Temperature Max', [-7,-6,10,15]) .set_global_opts(title_opts=opts.TitleOpts(title="Temperrature throught out the year", subtitle="2021")) ) bar.render_notebook()
We saw the common dark mode theme let’s check some other interesting themes also. Well, I do prefer this purple palate! I have never seen such a good purple check box palate theme for the chart.
from pyecharts.charts import Bar from pyecharts import options as opts from pyecharts.globals import ThemeType bar = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION)) .add_xaxis(['JAN','FEB','MAR','APR']) .add_yaxis('Temperature Max', [7,6,15,10]) .set_global_opts(title_opts=opts.TitleOpts(title="Temperature of India", subtitle="2021 Year")) ) bar.render_notebook()
There are some other palates to try them out I am listing them WHITE, LIGHT, DARK, CHALK, ESSOS, INFOGRAPHIC, MACARONS, ROMA, ROMANTIC, SHINE, VINTAGE, WALDEN
Let’s try out the pyechart library by starting with the bar chart. Here, I have taken demo data of the Temperature of India for 4 months Jan, Feb, Mar, Apr.
This bar chart shows the one parameter Temp Max but if you want another parameter too like temp min then it is simple just add another y-axis. Let’s see how it is done.
We saw how to make a simple bar chart let’s add some specific details so when our audience sees the charts they don’t fail to miss out on the details.
from pyecharts.charts import Bar bar = ( Bar(init_opts=opts.InitOpts()) .add_xaxis(['JAN','FEB','MAR','APR']) .add_yaxis('Temperature Max', [-7,-6,10,15]) .add_yaxis('Temperature Min', [-1,0,5,12]) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max", name="Highest Temp"), opts.MarkPointItem(type_="min", name="Lowest Temp")] ), ) ) bar.render_notebook()
If we want to download the charts we just need to add ToolboxOpts to the chart and it will show a download option on the chart.
Want to see a unique way to represent the value in percentage pyecharts data that have liquid charts. In liquid charts, we need to give the value which we want to see on the chart in decimal format. This chart is a unique chart that will not only show the value but also the background has water which is running all the time. I haven’t seen this type of chart till now.
To make this type of chart just run the below line of code
c = ( Liquid() .add("Completion", [0.67]) .set_global_opts(title_opts=opts.TitleOpts(pos_left="center")) ) c.render_notebook()
We can modify the chart by color and outline parameter. like if we want to choose any other color than the default blue. We just need to give a color name in the color parameter and for the outline, if we want to hide it then just need to make is_outline_show=False
For changing the color of the circle just give a color name to the color parameter.
The scatter chart which we are going to see is not a normal bubble chart the scatter chart will have a ripple effect. The scatter chart with ripple effects of each dot and also have a slide bar from where we can slide to filter the data. Isn’t that amazing?
We saw how to make a scatter plot with a ripple effect let’s add two y-axes and compare the data.
We saw how to have 2 data points for comparison let’s see how we can have a sidebar that will tell us where the data point lies compared to others.
c = ( EffectScatter(opts.InitOpts(width='900px', height='500px')) .add_xaxis(x) .add_yaxis("Temp1", v1,is_selected = True,symbol_size = 20, symbol=SymbolType.DIAMOND) .add_yaxis("Temp2", v2,is_selected = True,symbol_size = 20) .set_global_opts(title_opts=opts.TitleOpts(title="Temperature of India", subtitle="2013-2020 Year"), visualmap_opts=opts.VisualMapOpts(pos_left="right", type_="color", max_=2000, min_=0, pos_bottom=50) ) ) c.render_notebook()
Here we saw what is Pyechart Data and what are the benefits of pyecharts. As there are dynamic which helps the audience to engage with them with additional functionality that it is in scatter chart we have a ripple effect.
You can contact me through the below-mentioned social media platforms.
LinkedIn | Kaggle | Medium | Analytics Vidhya
Leave a Reply Your email address will not be published. Required fields are marked *