Skip to content
Search
Generic filters
Exact matches only

5 Magical Tricks to improve your Visualization Design using Matplotlib | by Anass El Houd | Aug, 2020

It is impossible to know everything, no matter how much our experience has increased over the years, there are many things that remain hidden from us. This is normal, and maybe an exciting motivation to search and learn more. And I am sure that this is what drove you to this article.

We know that one of Matplotlib’s most important features is its ability to play well with many operating systems and graphics backends. Matplotlib supports dozens of backends and output types, which means you can count on it to work regardless of which operating system you are using or which output format you wish [1].

I am sharing with you 5 magical tricks and new features I didn’t know about before, to improve your design and visualization skills using Matplotlib. These tricks will lend a helping hand to your work and make it more professional.

In case one of these features did not work for you, please update your Matplotlib version using:

pip install -U matplotlib

Without further ado, let’s get started!

Our first trick for today is annotations which are types of comments added to a plot at a point to make it more understandable, clarify more information, or define the role of that point.

To do so, we are going to use plt.annotate() function from Matplotlib. It allows you to create arrows, join them, and make them point to a specific zone. You can adapt the lines above to your own code:

This method will definitely help you to present your work either in writing, in a Latex report, Ph.D. defense, and so on…

I think this is the most magical trick to mention. This new feature is so helpful and interesting, especially for researchers and data scientists. The method indicate_inset_zoom() returns a rectangle showing where the zoom is located which helps you show a specific part of the curve without plotting another one.

The code above explains how to call the method and add it to your plot:

This trick is useful for solving copyrights issues. It helps you add your watermark to your visualization design. It is not very widely used but it is still an important feature to know about when preparing your visualization project. In this feature, you can either use a text watermark or an image watermark.

Text Watermark

To add a text watermark, you can use the line below:

You can also use your logo or your company’s logo as a watermark by changing the lines 11, 12, and 13 on the code above.

Image Watermark

Once you added your logo to the same directory as your main file, you can use this code instead of the text watermark. Do not forget to modify “tds.png” by your own logo name:

These new methods allow sharing axes immediately after creating them. Which gives an attractive and arranged look to your visualizations. Please make sure you update your Matplotlib version before using the code because this method is a newly published feature.

The code source is written below:

This trick is useful for Data Scientists and Machine Learning Engineers as well. It creates an infinite line passing through two points. It can be useful for separating clusters, groups, or plots.

Use the following code source to check this feature and let me see how would you apply it in your data visualization project:

Data Scientist, ML Engineer, Data Analyst, or Business Analyst, you are surely aware of the power of Matplotlib and what is capable of. It is one of the best tools that help us tell stories efficiently and powerfully, linking our analysis to business objectives and get interpretation and decisions as results.

With these features, you will be able to add both elegance and professionalism to your academic or official projects. And you will make it easier for the readers and reviewers to understand and keep track of the information and the interpretation resulted from the data visualization.

There is just something extraordinary about a well-designed visualization: the colors stand out, the layers harmonize, the contours fit into the whole design, and it not only has a beautiful aesthetic quality but also gives us a meaningful insight. You know that data visualization is like telling a story, that’s why you should make it professional and enjoyable as much as you can.

In the end, note that if you are not familiar with Matplotlib, I recommend you check this interesting article for beginners.

Thank you for reading. Stay tuned and follow for upcoming features!

[1] Jake VanderPlas (November 2016). “Python Data Science Handbook”. Published by O’Reilly Media, Inc.