Introduction to Best Parallel Plot Python Library: “HiPlot” | by Moto DEI | Towards Data Science

HiPlot is Facebook’s Python library to support visualization of high-dimensional data table, released this January. It is particularly well known for its sophisticated interactive parallel plot.
Before anything, take a look at their compelling demo video. This explains how high its interactivity is, which we would appreciate when we do EDA.
, and play around their demo app with sample data here. Do not forget to select the range on axis and hold-and-move to check the interactivity.
HiPlot is not just good looking, but also has following four appreciated characteristics:
Very easy to implement
Implementing the parallel plot using their hiplot module is literally by one line and almost a no-brainer.
Highly interactive
As you can see in the demo video above, the plot is highly interactive. Giving some mouse clicks lets you deep dive to any subset of data.
Run fast
Despite its appearance, the runtime to visualize the large dataset as a parallel plot is short. Let’s see this later.
Native HTML rendering function
They prepared a native function to turn the parallel plot to HTML code (hooray!!) Produced HTML page can be downloaded as .html file or deployed from Flask with almost no additional rendering effort. I tried to run it on heroku through Flask in the exercise below.
Thanks to these benefits, I believe HiPlot is one of first-choice tool sets for EDA in data analysis project before jumping in other time-consuming visualizations.
Let’s take a look at each of the benefits one by one.
Let’s see how easy it is to get you started with HiPlot using the famous iris data set.
Installation of HiPlot is just as easy as ordinary modules. Just use pip:
pip install -U hiplot
To use external csv file, you even do not have to use Pandas DataFrame. They prepared a native method to run parallel plot directly from csv file as such Experiment.from_csv(). When you need to use DataFrame, use Experiment.from_dataframe() instead. And it is totally fine to use Jupyter Notebook.
import hiplot as hipiris_hiplot = hip.Experiment.from_csv('iris.csv')iris_hiplot.display()
And here’s what you will see:
You are going to love HiPlot once you start playing around.
As you already saw in the demo movie above, here are some examples of the uses of interactive chart.
To test the run time to show the parallel plot for larger data, I used Kaggle FIFA 19 complete player dataset. It is a dataset from a video game “FIFA 19”, as the name explains a game of soccer (or you may call football), where you can play as a team manager of a actual soccer team or as an actual soccer player. The dataset contains the all playable characters list with their skill levels (e.g. how good they are at heading, free kick etc.) The number of rows is 18,207 and of columns is 89. The first row is Messi from Argentina.
To do the performance test, I intentionally make the data size 10 times larger. I concatenated the FAFA 19 dataset 10 times, ended up with having 182,070 rows. Usually, visualizing large data set takes time to run and causes huge latency after the chart shows up. Interactivity? Forget and rerun the script! What about HiPlot?
I ran HiPlot on 182,070 rows x 89 columns dataset without any edits. It took 81 seconds to process and additional 5 mins to display the graph. I think it is short enough for its size.
fifa = pd.read_csv('fifa19_data.csv',index_col='Unnamed: 0')fifa_extended = pd.concat([fifa,fifa,fifa,fifa,fifa,fifa,fifa,fifa,fifa,fifa],axis=0,ignore_index=True,sort=False)fifa_hiplot = hip.Experiment.from_dataframe(fifa_extended)fifa_hiplot.display()
What is even greater about HiPlot is that data size does not harm its interactivity too much. After selecting the range on axis, it tries to show only the plots belonging to the range. This change re-renders the plot almost within a second, which is surprising quick compared to other visualization tools.
When we want to share the plot with someone else, we may run the code on notebook and copy-and-paste the plot, but it removes the graph interactivity.
HiPlot has its native HTML rendering function Experience.to_html(), which returns HTML file with the plot embedded with just one line of code.
Let me go with the original rows and fewer columns from FIFA 19 dataset for simplicity.
fifa = pd.read_csv('fifa19_data.csv',index_col='Unnamed: 0')fifa_small = fifa[['Age','Nationality','Value','Height', 'Weight', 'Crossing', 'Finishing', 'HeadingAccuracy', 'ShortPassing', 'Volleys', 'Dribbling', 'Curve', 'FKAccuracy', 'LongPassing', 'BallControl', 'Acceleration']]fifa_hiplot = hip.Experiment.from_dataframe(fifa_small)fifa_hiplot.display()
This code will produce a new .html file on your local with the plot.
_ = fifa_hiplot.to_html("fifa_hiplot.html")
Now you can share the .html file directly with your team members to let them play around the plot.
Since Experience.to_html() returns html code, it’s even just easily connected to web server and deploy the plot externally.
Let me try it with Flask and Heroku. As I explained a lot here, I needed four files pushed to GitHub repository, to be synced with Heroku app.
fifa19_data.csv: FIFA19 dataset file.
hiplot_fifa.py: Python code to run and kick off Flask app.
import hiplot as hipimport pandas as pdfrom flask import Flaskapp = Flask(__name__)@app.route('/')def fifa_experiment():    fifa = pd.read_csv('fifa19_data.csv',index_col='Unnamed: 0')    fifa_hiplot = hip.Experiment.from_dataframe(fifa[['Age','Nationality','Value','Height', 'Weight', 'Crossing','Finishing', 'HeadingAccuracy', 'ShortPassing', 'Volleys', 'Dribbling', 'Curve', 'FKAccuracy', 'LongPassing', 'BallControl', 'Acceleration']])           return fifa_hiplot.to_html()if __name__ == "__main__":    app.run()
requirements.txt: a requirement file for Heroku to install the necessary modules.
gunicorn==19.9.0pandas==0.24.2hiplot==0.1.12Flask==1.1.1
Procfile: a start-up command for Heroku to run when it starts the app.
web: gunicorn hiplot_fifa:app
Sync the code files and make a set up on Heroku. Opening the web app gives the following HiPlot graph page, which is globally accessible through domain name.
In this post, I introduced the HiPlot the current best option of parallel plot to start EDA to take a look at the variable interaction overview.
It is easy to run, highly interactive, fast, and with much shareable through HTML file or code.
Although the data science projects definitely need further investigation such as looking at the shape of distribution of values, imputing the missing values etc, HiPlot would be a much help to start off the data preprocessing and understanding.