Create Plotly Express charts in less lines of code using Python and Datamallet
In this article, we will see how to create all possible Plotly express charts in very less lines of code using a new Python Module known as datamallet.
Introduction to the datamallet Library
According to the PyPi website datamallet library is made by Data Scientists to help fellow Data Scientists easily Visualize data in the least amount of line of code possible. It is a collection of different functions of different famous Python libraries, it encapsulates functionalities of Scikit-Learn, Plotly, Pandas, Numpy, and SciPy modules to provide Data Scientists with a one-stop solution for all kinds of Data Visualization and Manipulation.
To install it simply write the following command in the terminal:
pip install datamallet
The Datamallet library is only supported by the Python versions mentioned in the following image. It only supports Python 3.9, I have tried to install it in both 3.10 and 3.11 but failed in both, so if the user has Python version <= 3.9 they are good to go.
Importing the Modules
Now we will import pandas This library helps to load the data frame in a 2D array format and has multiple functions to perform analysis tasks in one go. This library helps to load the data frame in a 2D array format and has multiple functions to perform analysis tasks in one go.
We will be using the AutoPlot class from the visualization module of datamallet (As it is mentioned earlier that datamallet itself has no special functions, it encapsulates functionalities of different modules).
After importing we will read our dataset using pandas and initialize a variable with the AutoPlot so that we can use that variable further to perform operations. Also, we will use that variable to print out all the possible charts which can be created / available in the visualization module.
As you can see, we are using a variable dataframe to read and store our csv file and then using the variable auto to initialize AutoPlot by passing our dataframe, df is the parameter that indicates the dataframe which we will visualize. Then using the chart_type() method of AutPlot class to print all the possible list of charts available as a list, as the output of chart_type() is a list we are using a for loop to iterate over it to print all the types in different lines for better understanding.
Creating all the Plots
The AutoPlot class plots all the plots into an HTML file whose name we have to provide as its parameter while initializing the AutoPlot class. The AutoPlot will create an HTML file named plots inside which it will create all those aforementioned plots. You can download the dataset used from here.
By default, AutoPlot doesn’t plot the following kinds of plots because it would take more time for them to be plotted and a lot more images need to be embedded into that HTML file.
But we can add this parameter while Initializing AutoPlot to True and those will be added to our HTML file. As shown in the above code we have used the iris dataset and included 11 different types of plots in one go using a single function.
Here I am trying to plot all the possible plots that are available in the module, due to this the HTML file will take a huge time to load, or if the user’s device is not that powerful and the dataset used is huge then it might never open (crash the browser). It is not recommended to try to plot every possible plot at the same time because that will take a huge time and computing power. But for this tutorial’s sake, I am trying to show how the HTML will look if we try to plot every single one.
If we compare this output with the previous output we will see here lots of new plots are being added. If some plots can’t be established due to the dataset (like those plots which require mathematical calculations and must have a certain amount of columns and values or can only be plotted if there are numerical values) then this will not throw any error, only it will not plot those.
Please Login to comment...