Digging Deep Into Plots: Raising the Bar
Guidelines to make your Bar Charts appealing and how to do that using Python
Python, being an open-source language, has a variety of libraries which enable us to do tasks within seconds which would otherwise take days to code and hours to compute.
People who use Python as a Data Science tool are well aware of Matplotlib and Seaborn. Plotting a graph using a single line of code is one of the specialities of these libraries.
If you want to plot to just understand your data, then these one-liners would come handy. But, if you want your plots to be presentable, minimalistic and devoid of any visual clutter, you might want to work a little harder.
Welcome to the Episode I of Digging Deep Into Plots (note the pun!). I will name this episode as Raising the Bar (Again, A PUN).
First of all, let us discuss the important points that should be kept in mind to make your Bar Plots presentable-
1. Use Vertical Bars when your data is Chronological or when you have negative values
2. Horizontal Bars work best when your data has a lot of different categories
3. Start the Y-Axis at Zero
4. Use the same colour for all the bars
5. Keep Labels and Titles short
6. Avoid putting a Grid in the Background
7. Annotate your bars and avoid the values axis if no. of bars are less in number (2–6)
Now, let us dive into Python. I will be using a simple predefined table and not a DataFrame so that we can focus on our aim.
By writing simple one-line code, we get the following Bar Chart-
First of all, these bars should not be of different colours as discussed in the points above, let us change that-
You know what, these would look better if we arrange them in ascending or descending order-
Also, let us switch the axes. When we use Categorical Data, it is preferred to put the bars horizontally-
Let us remove the border, it is unnecessary (sns.despine() function will help us here)-
Rather than using the x-axis for scale, let us annotate so that we do not have to hunt for values-
This looks neat, right?
THE FINAL CODE-
And the Final Chart-
If you want to check out a video guide to the above process, click the link below (and don’t forget to send a connection request)
The step-by-step notebook is uploaded in my GitHub below. Check out!
LinkedIn- https://www.linkedin.com/in/iasarthak/
GitHub- https://github.com/iasarthak
Also, this was my first blog post and I hope to improve. It would be great if you drop in some reviews! Thanks for staying till the end.