Seaborn is still little known but it has the wind in its sails. In reality, if you operate in data analysis, it will quickly seem essential to you. Better yet, training in its use will seem essential. The reason ? From a few concise instructions, Seaborn can produce informative, very useful and good-looking graphics. So how can you resist?
If you’re a data scientist, chances are you use Numpy to view and process your arrays of data. By nature, databases integrate a lot of information and therefore, a library such as Numpy for Python is extremely useful in terms of highlighting trends, statistics, situations worthy of our attention.
That being said, it goes without saying that a good graph will always speak louder than a summary table. A curve, a histogram, will be able to bring out at first glance a phenomenon to which we are trying to draw attention. The deal is clear: in terms of graphical representation in Python, you also know that it is possible to use the Matplotlib library to plot the graphs of your choice, without potential limit.
However, since around 2020, another solution has been regularly mentioned: Seaborn, a Python library for data visualization. Admittedly, Seaborn is much less known than Matplotlib and moreover, there is very little information on its actual use, for example, we do not know if it has been adopted by major companies. Its own creator seems unconcerned to promote these aspects related to a potential popularity of Seaborn. In reality, it is only recently that we have seen a major rise in the rating for Seaborn.
To put it simply: once you have tried Seaborn, it often seems difficult to switch back to Matplotlib!
Seaborn versus Matplotlib
Question: why would we benefit from using Seaborn rather than Matplotlib? As we will see, the answer is multiple.
Matplotlib is not easy to use
It would be difficult to question the power of Matplotlib. However, we have to recognize it: its use is not always easy. The concern comes above all from the versatility of the Python Matplotlib library which offers an almost incalculable number of options of all kinds. Sometimes it’s hard to get the desired result. We follow a tutorial and surprise: on arrival, the graphics obtained do not conform to what we should have obtained. The reason is often related to a very slight error in the syntax of Matplotlib.
Matplotlib: two approaches
If Matplotlib can seem intimidating and even disconcerting, it is also because it is based on two possible approaches,
- object oriented programming
- use of Matplotlib functions.
Each of these approaches will be based on a syntax of its own, but let’s face it, for the novice who approaches this tool, there is sometimes enough to lose his Latin since we are dealing with two different types of formulations to arrive at the same result.
Matplotlib curves are not always practical and aesthetic
The other criticism sometimes addressed to Matplotlib is that by default, a large number of representations lack grace. To make them attractive but also useful, it is necessary to dig into the parameters, to intervene on the thickness of the lines, to use a “color map” (color map), etc. In short, getting a nice result often involves writing lines and lines of code. Is this really the expected task of a data scientist? Wouldn’t it be better if he spent his time producing the desired graph rather than struggling with so many parameters?
Seaborn has arrived…
It is from such reflections that a man named Michael Waskom, researcher in data analysis, realized Seaborn. Waskom relied on the Matplotlib library but also on Pandas, which, let’s remember, is dedicated to data analysis in Python. Seaborn was released to the public in 2012.
If Seaborn’s strength had to be summed up in one sentence, it could be this:
Seaborn is able to achieve in one line of code what would take ten under Matplotlib!
Yes… Suffice it to say: if you’ve tried Matplotlib, the ease with which Seaborn can produce graphics is astounding. This is notably the case of the pairplot function which offers several possible representations of a data table. No sooner has the corresponding instruction been formulated than these multiple graphs appear, providing useful information on the various curves observed.
Another strong point: all the functions – or almost – of Seaborn have a standard form and therefore, you can easily reuse the code used for one on another. If you have weeks or months of Matplotlib practice behind you, we bet that such an opportunity is surprising and makes you want to know more.
Since this is so, how can one learn to master Seaborn? If you speak English well, then you can follow the tutorial offered on the official website of this library. You will then be able to practice on the proposed code examples.
Whatever the solution adopted, it is important to take the time to practice each example of such formations well and to assimilate the concepts and the syntax patiently. As so often with Python, the smallest detail can lead to an error and it is not always easy to spot it at first glance. What Seaborn can do to increase productivity is well worth the learning curve.
Important point: a good mastery of Seaborn ideally supposes having acquired a certain mastery of libraries such as Numpy and Pandas.
Is Seaborn the solution to everything?
You probably suspect it: Seaborn is not a universal solution, however. There are certain situations in which Matplotlib will be more appropriate. One thinks in particular of engineering applications. And if you are looking for a specialized and ultra personalized graph, you are more likely to find what you are looking for in Matplotlib. In short, Seaborn is above all adapted to the representation of statistical data.
That being said, some Python users favor a third choice: Plotly Express, which is similar in ease of use and has plenty of sample plots in its documentation.