The world’s leading publication for data science, AI, and ML professionals.

Mito: One of the Best Python Libraries For Data Visualization

Let's explore one of the coolest Python libraries for data analysis

PYTHON

A few months ago, I wrote a blog about Mito, a handy Python library with a graphic user interface (GUI), turning data analysis just as easy as working with Microsoft Excel. For those who are learning Python or work with it daily, it’s a helpful tool. However, in my first blog, I mainly focused on how to accomplish data analysis, data cleaning, data modification tasks, etc. Now, it’s time to go over one of the tasks where Mito shines: Data Visualization.

What is Mito?

Mito is a Python library with GUI that allows us to do data cleaning, data manipulation, analysis, and visualization with a few clicks.

You might ask yourself: Python with a user interface? Why should we even consider it? Well, it’s an excellent tool for people learning Python. It makes it easier to accomplish tasks requiring multiple lines of code, and even though you are using a GUI, Mito shows us the code generated to get the job done, which can improve learning speed. It’s also a great tool for professionals because you can do tasks that would take minutes in seconds.

Too good to be true (or free)?

Whenever something sounds too good to be true, I ask myself if it’s too good to be free. The good news is that Mito is open-source and free to use! They have paid plans, but I’ll use the open-source version in this blog.

Since they have paid plans, I need to say that I don’t write sponsored content, and it’s not different for this blog. I have not been paid in any way. My honest opinion is based on my experience with this library.

Getting Started

Installing is easy, and their GitHub page is very informative in case you have any issues installing Mito. To simplify the process, you can just copy and paste the following code on your terminal and you will be good to go:

On Mac:

python3 -m venv venv;
source venv/bin/activate;
pip install -r requirements.txt;
python -m mitoinstaller install

On Windows:

python3 -m venv venv
venvScriptsactivate.bat
pip install -r requirements.txt
python -m mitoinstaller install

Now, you can open Jupyter Lab from your terminal. To start using Mito, you just need to import it and type the following command to start a new sheet:

import mitosheet
mitosheet.sheet()

Cool. Let’s pause here and explore Mito’s UI. If you are familiar with Microsoft Excel, you will see many familiarities with Mito. One cool thing about this library is that you can see the column’s datatype at first glance. We can also see many functions, such as importing files, adding columns, deleting columns, changing datatype, changing number type (integer, float, adding or removing decimals), pivoting data, and creating graphs. I have covered some of these features in my first blog about Mito. Today, let’s focus on building some charts.

Now that we are familiar with Mito’s UI, let’s use the Supermarket Sales dataset, which contains multiple datatypes that will allow us to create some interesting visualizations. You can find the dataset here. Importing files to Mito could not be any easier. Just click on Import Files, and we are good to go.

One cool thing to know is that you can see the features’ datatype under the column name, which is already saving us from typing code for some data exploration.

To start, why don’t we visualize total sales by date? To do so, click on Graph, and a side menu will appear. Select the chart type, then the x-axis (I will use the date for this visualization), the y-axis (total, which is the total sales for that client), and done. We just created a graph in seconds.

One thing to notice is that a new tab was created for the chart. This helps us organize the content of our notebook.

Now we can make some changes to the graph. Let’s change the chart title to Sales by Date and the y-axis to Total Sales.

We can also transform the axis to linear, log, categories, etc. We won’t be doing these transformations today, but you can try them on your end. There are other paid features to edit the charts, but since I’m only using the open source today, let’s skip those. Also, you can change the code yourself without having to pay for it.

The graph I created only tells us a little. Let’s explore some more options to make it insightful. First, we can easily change the chart type – such as scatter plot, line, histogram, density heat map, violin, strip, etc. We can also change the color to different categories by clicking on Color by Column. Easy Breezy!

If you pay attention to the chart we have so far, you will see that the dates need to be more organized and in order. That’s because the date datatype is string. We need to change it to DateTime type, which is very simple.

Go to the dataframe tab, find the column you want to change the datatype, click on the datatype icon (str, in this case), and choose the datatype you want to change. Looking at the graph below, you will see that the dates are now ascending.

One thing to notice is that Mito generates the code used to change the data type. The other cool thing is that anyone can run this notebook using the code Mito generated, even if they don’t have Mito installed.

Back to our graph, you noticed that we have two tabs now. Let’s rename the charts tab to make things more organized. Just click on the tab, and you will be able to change its name of it.

The chart we have so far is interesting, but it doesn’t tell us much. Let’s make it more insightful by looking at which cities had the most sales by date.

To do so, we will change the Color by Column to City and then click on histogram to change the chart type. Once it’s done, we can export the chart. Let’s copy the code and see if we can run it. To copy the code, click on Export, and choose the option Copy the code that displays graph. Now we can paste the code in any cell in Jupyter notebook.

Awesome! We created a beautiful chart, generated the code, and ran it in our notebook. Let’s take another look at the graph and code generated by Mito.

import plotly.express as px
# Construct the graph and style it. Further customize your graph by editing this code.
# See Plotly Documentation for help: https://plotly.com/python/plotly-express/
fig = px.histogram(supermarket_sales, x='Date', y='Total', color='City', histfunc='count')
fig.update_layout(
    title='Sales by Date', 
    xaxis = dict(
        showgrid=True, 
        rangeslider = dict(
            visible=True, 
            thickness=0.05
        )
    ), 
    yaxis = dict(
        title='Total Sales', 
        showgrid=True
    ), 
    legend = dict(
        orientation='v'
    ), 
    barmode='group', 
    paper_bgcolor='#FFFFFF'
)
fig.show(renderer="iframe")

That’s a nice-looking graph created using Plotly, and it took only a few seconds to be done. If we look at the code, it takes multiple lines of code to achieve the same result, and the graph is ready to be added to a presentation, for instance.

Ok, let’s create one more graph, checking which product lines sell the most by gender. Click on Graph, then select histogram for the datatype, Gender for the x-axis, Product Line for the y-axis, Product Line for Color by Column, and it’s done. Let’s copy and paste the code generated and see if we can print the results in the notebook.

Once again, it worked, and it took only a few seconds. Cool, right?

Final Thoughts

Today we went over how to use Mito for data visualization. There are much more tasks that Mito can accomplish, and their team is continuously adding features to make it even more helpful. The big question is: should you use it? You should try it even if you have been using Python for years. It can make tedious and time-consuming tasks in seconds so that you can save use your time with more challenging ones.

I believe that education should be available for everyone, and Mito helps people who are starting a new career or are thinking of learning Python but have no idea where to start. On top of that, it can help people who work with Python and need to write repetitive code daily. Thus, instead of typing dozens of lines of code, they can achieve the same results with 3 or 4 clicks.

You can try it out and see where Mito can be applied for you. Everyone can find use cases for this incredible Python library. If you decide to test it, let me know how it went. Happy Coding!

You May Also Like:

Mito: One of the Coolest Python Libraries You Have Ever Seen

D-Tale: One of the Best Python Libraries You Have Ever Seen

4 Amazing Python Libraries That You Should Try Right Now


Related Articles