Daily Dose of Data Science

Share this post

Matplotlib Has Numerous Hidden Gems. Here's One of Them.

www.blog.dailydoseofds.com

Discover more from Daily Dose of Data Science

High-quality insights on Data Science and Python, along with best practices — shared daily. Get a free 550+ page data science PDF guide and 450+ practice questions notebook.
Over 50,000 subscribers
Continue reading
Sign in

Matplotlib Has Numerous Hidden Gems. Here's One of Them.

A cool trick to improve Matplotlib plots.

Avi Chawla
Mar 29, 2023
3
Share this post

Matplotlib Has Numerous Hidden Gems. Here's One of Them.

www.blog.dailydoseofds.com
Share

One of the best yet underrated and underutilized potentials of matplotlib is customizability. Here's a pretty interesting thing you can do with it.

By default, matplotlib renders different types of elements (also called artists), like plots, legend, texts, etc., in a specific order.

But this ordering may not be desirable in all cases, especially when there are overlapping elements in a plot, or the default rendering is hiding some crucial details.

With the zorder parameter, you can control this rendering order. As a result, plots with higher zorder value appear closer to the viewer and are drawn on top of artists with lower zorder values.

Lastly, in the above demonstration, if we specify zorder=0 for the line plot, we notice that it goes behind the grid lines.

You can find more details about zorder here: Matplotlib docs.

Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new about Python and Data Science every day.

👉 Tell me you liked this post by leaving a heart react 🤍.

👉 If you love reading this newsletter, feel free to share it with friends!

Share Daily Dose of Data Science


Find the code for my tips here: GitHub.

I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn and Twitter.

3
Share this post

Matplotlib Has Numerous Hidden Gems. Here's One of Them.

www.blog.dailydoseofds.com
Share
Previous
Next
Comments
Top
New
Community

No posts

Ready for more?

© 2023 Avi Chawla
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing