Daily Dose of Data Science

Share this post

A Simple Trick That Significantly Improves The Quality of Matplotlib Plots

www.blog.dailydoseofds.com

A Simple Trick That Significantly Improves The Quality of Matplotlib Plots

A simple one-liner to go from dull to sharp plots.

Avi Chawla
Apr 12, 2023
17
1
Share

Matplotlib plots often appear dull and blurry, especially when scaled or zoomed. Yet, here's a simple trick to significantly improve their quality.

Matplotlib plots are rendered as an image by default. Thus, any scaling/zooming drastically distorts their quality.

Instead, always render your plot as a scalable vector graphic (SVG). As the name suggests, they can be scaled without compromising the plot's quality.

As demonstrated in the image above, the plot rendered as SVG clearly outshines and is noticeably sharper than the default plot.

The following code lets you change the render format to SVG. If the difference is not apparent in the image above, I would recommend trying it yourself and noticing the difference.

from matplotlib_inline.backend_inline import set_matplotlib_formats
set_matplotlib_formats('svg')

Alternatively, you can also use the following code:

%config InlineBackend.figure_format = 'svg'

P.S. If there’s a chance that you don’t know what is being depicted in the bar plot above, check out this YouTube video by Numberphile.

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

👉 Read what others are saying about this post on LinkedIn.

👉 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.

17
1
Share
Previous
Next
1 Comment
D.W. Eversole
Writes Outside The Box
Apr 12Liked by Avi Chawla

nice post

Expand full comment
Reply
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